Aleš Sýkora / November 28, 2023 / 0 comments

Child posts menu for custom post type parent item

Post summary: This code will help you display menu of childs on current post. For example: Product 1 = parent has those child pages: – Product usage- How to- Disclaimer- Calculator When you put this child items menu in your template, it will show all childs of product 1 on all child pages and also on product…

This code will help you display menu of childs on current post. For example:

Product 1 = parent has those child pages:

– Product usage
– How to
– Disclaimer
– Calculator

When you put this child items menu in your template, it will show all childs of product 1 on all child pages and also on product 1 parent page.

<?php
global $post;
if($post->post_parent)
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&post_type=nabidka");
else
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&post_type=nabidka");
if ($children) { ?>
    <ul id="child-menu">
    <?php echo $children; ?>
    </ul>
<?php }
?>

So you can build layouts like this:

(P= Parent page, CH = child)

Fuel my passion for writing with a beer🍺

Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻

0 comments

Share Your Thoughts