简体   繁体   中英

Wordpress list child pages of custom post type

Im stuck on this and any help would be appreciated.

Say there is a parent page called "Stuff". And Stuff has several pages under it.

  • Stuff
    • more stuff
    • more stuff1
    • more stuff2
  • It has no children
  • Other with children
    • etc
    • etc 2

So when you click on "more stuff". That page would list all the pages under stuff ('more stuff, morestuff1, morestuff2'). Or if you click on "etc" you would see "etc, etc2"

Any thoughts or help would be appreciated. I'm using the Types plugin and have hierarchical setting turned on already.

You can use the wp_list_pages function. In http://codex.wordpress.org/Function_Reference/wp_list_pages , scroll down to the section with sub-heading "List subpages even if on a subpage" to see an example. Just make sure to pass the post_type parameter like this and include the code inside the loop of your single template file:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM