Skip to content

Instantly share code, notes, and snippets.

@Jehu
Last active February 16, 2022 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jehu/f6b71aa4168be0e9cf661039cb601bae to your computer and use it in GitHub Desktop.
Save Jehu/f6b71aa4168be0e9cf661039cb601bae to your computer and use it in GitHub Desktop.
WordPress: Menu for Child pages (Split Menu)
<?php
function mwe_get_parent_title() {
$post = get_post();
return get_the_title($post->post_parent);
}
function mwe_get_sidebar_menu() {
$post = get_post();
if ( is_page($post->ID) && $post->post_parent ) {
$children = get_pages(array(
'child_of' => $post->post_parent,
'sort_column' => 'menu_order',
)
);
} else {
$children = get_pages(array(
'child_of' => $post->ID,
'sort_column' => 'menu_order',
)
);
}
?>
<ul class="submenu">
<?php
foreach ($children as $child) {
$is_active = ($child->ID === get_the_ID()) ? 'active' : '';
?>
<li class="submenu__item"><a class="submenu__link <?= $is_active ?>" href="<?= get_permalink($child->ID) ?>">
<?= $child->post_title ?>
</a></li>
<?php } ?>
</ul>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment