【问题标题】:wordpress showing siblings of current page w/bootstrapwordpress 用/bootstrap 显示当前页面的兄弟姐妹
【发布时间】:2012-12-21 03:43:42
【问题描述】:

我正在自定义一个 wordpress 主题,我正在尝试实现一个子菜单,它只显示当前页面的同级页面,不包括我所在的页面。例如,如果结构是:

水果
--苹果
--梨
--橙子

我在“Apples”上,子菜单会显示“pears”和“oranges”的链接。

另一个转折是我正在使用 twitter bootstrap 进行样式设置。我有下面来自http://wp-snippets.com/list-subpages-and-siblings/的wordpress功能:

<?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>

有没有人有任何提示或指示让我上路?谢谢,马特

【问题讨论】:

    标签: php html wordpress twitter-bootstrap


    【解决方案1】:

    你可以放一个 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      相关资源
      最近更新 更多