Wordpress列出自定义帖子类型的子页面

时间:2014-07-28 22:03:19

标签: php wordpress custom-post-type

我坚持这一点,任何帮助将不胜感激。

假设有一个名为" Stuff"的父页面。而Stuff下有几页。

  • 东西
    • 更多东西
    • more stuff1
    • more stuff2
  • 没有孩子
  • 其他有孩子的
    • etc 2

所以当你点击"更多的东西"。该页面将列出所有页面下的内容('更多内容,morestuff1,morestuff2')。 或者如果你点击"等等#34;你会看到" etc,etc2"

任何想法或帮助将不胜感激。我已经使用了类型插件,并且已经启用了分层设置。

1 个答案:

答案 0 :(得分:0)

您可以使用wp_list_pages功能。在http://codex.wordpress.org/Function_Reference/wp_list_pages中,向下滚动到子标题“列出子页面即使在子页面上”的部分,以查看示例。只需确保像这样传递post_type参数,并将代码包含在单个模板文件的循环中:

<?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 }
相关问题