Skip to content

Instantly share code, notes, and snippets.

View christiaansnoei's full-sized avatar

Christiaan Snoei christiaansnoei

View GitHub Profile
// If is template
@if( is_page_template('resources/views/template-xx.blade.php') )
Show this when is template!
@endif
// Navigation
@if( has_nav_menu('navigation') )
{!! wp_nav_menu(['theme_location' => 'navigation', 'menu_class' => 'navigation_class']) !!}
@endif
@christiaansnoei
christiaansnoei / alpinejs-v2-open-div.html
Last active July 31, 2021 13:42
alpinejs-v2-cheat-sheet
<div x-data="{id: 1}">
<button @click="$dispatch('open-dropdown',{id})">Open</button>
</div>
<ul x-data="{ open: false }"
x-show="open"
@open-dropdown.window="if ($event.detail.id == 1) open = true"
@click.away="open = false">
Dropdown Body
</ul>
@christiaansnoei
christiaansnoei / wp-list-pages.php
Last active December 2, 2019 10:07
List all child pages of a parent page in WordPress.
<?php
global $post;
$ancestors = $post -> ancestors ?? '';
if( isset($ancestors) ):
$ancestors = array_reverse($ancestors);
if( isset($ancestors[0]) ):
$current_toplevel_menu_id = $ancestors[0];
else:
$current_toplevel_menu_id = $post -> ID;
@christiaansnoei
christiaansnoei / wp-custom-query.php
Created October 11, 2019 08:00
Create a custom query with WordPress.
<?php
$args = array(
'posts_per_page' => 99,
'post_status' => 'publish',
);
$posts = new WP_Query($args);
// Loop
if( $posts -> have_posts() ):
while( $posts -> have_posts() ): $posts -> the_post();
@christiaansnoei
christiaansnoei / twig_loop.html
Created September 26, 2019 05:54
Create a loop with Twig
{% set items = [
{
"title": "Title",
},
] %}
{% for item in items %}
{{ item.title }}
{% endfor %}
@christiaansnoei
christiaansnoei / acf-image-url-size.php
Last active August 23, 2019 11:09
Get an image url with a certain size.
<?php
$image = get_sub_field('image');
if( !empty($image) ):
$image_url = $image['sizes']['large'];
endif;
if($image_url):
?>
<img src="<?php echo $image_url; ?>" alt="" class="">
<?php endif; ?>
@christiaansnoei
christiaansnoei / acf-flexible-content.php
Last active January 20, 2022 10:51
Loop through each row of a flexible content field.
<?php
$flexible_content = '';
if( have_rows('partials', get_queried_object_id()) ):
while( have_rows('partials', get_queried_object_id()) ): the_row();
$row_layouts = [
'example-1',
'example-2',
'example-3',
];
@christiaansnoei
christiaansnoei / wp-featured-image.php
Last active October 11, 2019 08:01
Get the featured image in WordPress when set, if not a fallback will be loaded.