0
我正在處理一個主題,並且被卡在菜單上。該網站有幾個子頁面,這些頁面有孩子。我想實現的是當你點擊一個子頁面時,它只顯示一個帶有子頁面和子元素的菜單。僅顯示一個子頁面及其子元素
首頁
關於
活動
- 事件1
- 事件2
--Venue
--Food
--Music
- 事件3
聯繫
我想要的是當我點擊事件2時,它僅顯示事件2及其子女,而不顯示事件2的兄弟姐妹。
我目前的解決方案顯示所有的子頁面,即事件1,事件3。請在下面找到我的代碼。
<?php
// find parent of current page
if ($post->post_parent) {
$ancestors = get_post_ancestors($post->ID);
$parent = $ancestors[count($ancestors) - 1];
} else {
$parent = $post->ID;
}
$children = wp_list_pages("title_li=&depth=2&child_of=" . $parent . "&echo=0");
if ($children) { ?>
<ul class="list-children">
<?php echo $children; ?>
</ul>
<?php } ?>