好的,自从我制作 WordPress 主题以来已经一年多了,现在我又开始了,但我在页面上的菜单上遇到了问题。
这是我当前的页面层次结构(我仍然只测试名称)
Home
This page
*Child 1
**Grandchild 1
**Grandchild 2
*Child 2
**Grandchild 3
**Grandchild 4
**Grandchild 5
*Child 3
**Grandchild 6
Another page
现在,当我访问“此页面”时,我想显示“此页面”(当前)和“此页面”的所有直系子级(此处没有孙子级)的链接,如此草图中:http://img840.imageshack。我们/img840/3006/thispage.png
现在,当我访问“此页面”的“孩子 1”时,我想在“孩子 1”下的子 ul 中显示上面菜单中的所有内容以及“孩子 1”(孙 1 和 2)的所有孩子,就像在这个草图中一样:http://img4.imageshack.us/img4/7868/child1.png
现在,当我访问“孙子 1”时,我想显示与“子 1”相同的菜单,仅将“孙子 1”作为当前项目,而不是像在这个草图中一样:http: //img819.imageshack.us/img819 /1633/grandchild1.png
这是我当前的代码,基于 wordpress codex 中的示例(在 wp_list_pages() 函数下),用于稍微其他类型的菜单,但它运行得不是很好,对于教子来说绝对不是很好。
<?php
if($post->post_parent){
$children = wp_list_pages("title_li=&include=".$post->post_parent."&echo=0");
$children .= wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
}
else{
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
}
if ($children) { ?>
<div class="page-menu">
<ul>
<?php echo $children; ?>
</ul>
</div>
<?php } ?>
正如您在草图中看到的那样,我的计划是将菜单作为我页面上的侧边栏。
那么有谁知道如何实现这一结果?