Child posts menu for custom post type parent item
Author: Aleš Sýkora, 1. 2. 2021
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)