Aleš Sýkora wrote

Child posts menu for custom post type parent item

1. 2. 2021 in

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)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More from category
Aleš Sýkora wrote
Translate fluent forms datepicker
27. 10. 2020 in
Need to translate fluent forms datepicker to your language? No problem.
Read More
Aleš Sýkora wrote
Change WP Rocket lazyload treshold
21. 1. 2021 in
Default treshold for lazyload is 300px in WP-Rocket. That means that images that are within 300px of the viewport (browser window) are loaded for smooth user experience. If you like to load less images – for example 100px after viewport only – you can not set it up directly in WP Rocket’s settings page. To […]
Read More
Aleš Sýkora wrote
Oxygen Dynamic repeater examples
14. 1. 2021 in ,
Query parent pagedata in Oxygen repeater Query parent page on child page. If current page is parent then query this page itself. Display all posts with same ACF post object field value Gets current post ID and look for posts connected to it by post object field from ACF.
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram