我正在定制一个wordpress主题,我正在努力实现一个子菜单,它只显示兄弟页面到当前页面,不包括我所在的页面。例如,如果结构是:
水果——苹果
——梨
——橘子
如果我在"苹果"上,子菜单会显示"梨"answers"橙子"的链接。
另一个转折是,我使用twitter bootstrap的样式。下面的wordpress函数是http://wp-snippets.com/list-subpages-and-siblings/:
<?php
global $wp_query;
if( empty($wp_query->post->post_parent) ) {
$parent = $wp_query->post->ID;
}
else {
$parent = $wp_query->post->post_parent;
} ?>
<?php if(wp_list_pages("title_li=&child_of=$parent&echo=0" )): ?>
<div id="submenu">
<ul class='breadcrumb'>
<?php wp_list_pages("title_li=&child_of=$parent" ); ?>
</ul>
</div>
<?php endif; ?>
我遇到了麻烦,弄清楚如何在输出链接(不包括最终链接)之后添加链接之间的分隔符,以及如何删除我正在打印的页面。
这是我想要的纯HTML标记:
<ul class="breadcrumb smaller-bread">
<li><a href="<?php echo site_url('/offerings/apples/'); ?>">Apples</a><span class="divider">-</span></li>
<li><a href="<?php echo site_url('/offerings/pears/'); ?>">Pears</a><span class="divider">-</span></li>
<li><a href="<?php echo site_url('/offerings/oranges/'); ?>">Oranges</a><span class="divider">-</span></li>
</ul>
有没有人有什么提示或指示让我在路上?欣赏,马特
你可以用IF !检查每个li,并根据当前URL检查它。类似这样的代码将为您提供当前页面:http://webcheatsheet.com/php/get_current_page_url.php
:
<?php if(! $pageURL == $curPageURL) ?>
<li> ... </li>
<?php endif; ?>
然后使用CSS添加边框,而不是分隔元素,例如:
ul.breadcrumb li {
border-bottom: 1px solid;
}
ul.breadcrumb li:last-child {
border-bottom: none;
}