WordPress子页和父页菜单
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WordPress子页和父页菜单相关的知识,希望对你有一定的参考价值。
Shows the sub pages of a parent page, and also the parent page as a link.
<?php if(!$post->post_parent){ // will display the subpages of this top level page $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); }else{ // diplays only the subpages of parent level //$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); if($post->ancestors) { // now you can get the the top ID of this page // wp is putting the ids DESC, thats why the top level ID is the last one $children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0"); // you will always get the whole subpages list } } if ($children) { ?> <ul> <?php $parent_link = get_permalink($post->post_parent); $parent_title = get_the_title($post->post_parent); if ($post->post_parent) { echo "<li><a href='".$parent_link."'>".$parent_title."</a></li>"; } else { echo "<li class='current_page_item'><a href='".$parent_link."'>".$parent_title."</a></li>"; } ?> <?php echo $children; ?> </ul> <?php } ?>
以上是关于WordPress子页和父页菜单的主要内容,如果未能解决你的问题,请参考以下文章