【发布时间】:2019-06-20 08:17:53
【问题描述】:
我在 WordPress 网站上有一个侧边栏菜单,它简单地输出该父级下的所有子页面。我正在尝试突出显示(或希望添加一个箭头)当前选择的子页面。我以有限的 PHP 经验遇到了困难,无法弄清楚如何做到这一点。
任何帮助将不胜感激。相关代码如下:
<?php
/* if the current pages has a parent, i.e. we are on a subpage */
if($post->post_parent){
/* $children = wp_list_pages("title_li=&include=".$post->post_parent."&echo=0"); // list the parent page */
$children .= wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); // append the list of children pages to the same $children variable
}
/* else if the current page does not have a parent, i.e. this is a top level page */
else {
//$children = wp_list_pages("title_li=&include=".$post->ID."&echo=0"); // include the parent page as well
$children .= wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&"); // form a list of the children of the current page
}
/* if we ended up with any pages from the queries above */
if ($children) { ?>
<ul class="submenu">
<?php echo $children; /*print list of pages*/ ?>
</ul>
<?php } ?>
我假设它会在输出部分,但我根本不知道如何定位当前正在浏览的子页面并相应地突出显示它。
【问题讨论】: