dtd14883 2015-08-08 16:16
浏览 55

Wordpress Custom Walker,定位第一个和最后一个链接

I have a custom walker set up in Wordpress:

class Custom_Walker_Nav_Menu extends Walker_Nav_Menu {
    function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
        if ( $depth )
            $indent = str_repeat("\t", $depth);
        else
            $indent = '';

        extract($args, EXTR_SKIP);
        $linkName = apply_filters( 'the_title', $item->post_title, $page->ID );
        $output .= $indent . '<li id="item_'.$item->ID.'"><a href="#" class="'.strtolower($linkName).'" data-filter=".'.strtolower($linkName).'">'.$linkName.'</a>';
    }


    function end_el(&$output, $page, $depth = 0, $args = array()) {
        $output .= "</li>
";
    }
}

Which outputs the following:

<nav role="navigation">
    <ul class="simple-nav">
        <li id="item_15"><a href="#" class="home" data-filter=".home">HOME</a></li>
        <li id="item_38"><a href="#" class="directing" data-filter=".directing">DIRECTING</a></li>
        <li id="item_40"><a href="#" class="compositing" data-filter=".compositing">COMPOSITING</a></li>
        <li id="item_42"><a href="#" class="visuals" data-filter=".visuals">VISUALS</a></li>
        <li id="item_74"><a href="#" class="contact" data-filter=".contact">CONTACT</a></li>
    </ul>
</nav>

The data-filter attributes are used by Isotope to filter my results. This works well for the directing, compositing and visuals links.

However for the first link, I would like to attach data-filter=".all" rather than .home

And for the last link, I want this to be an actual link to another page, rather than a blank link #.

How can I add further customisation to these links specifically?

Thanks

  • 写回答

1条回答 默认 最新

  • dtxpz8785 2015-08-08 16:52
    关注

    for first link try to change,

    $output .= $indent . '<li id="item_'.$item->ID.'"><a href="#" class="'.strtolower($linkName).'" data-filter=".'.strtolower($linkName).'">'.$linkName.'</a>';
    

    to

    if($item->post_title=='Home')
    {
    $output .= $indent . '<li id="item_'.$item->ID.'"><a href="#" class="'.strtolower($linkName).'" data-filter=".all">'.$linkName.'</a>';
       }
    else
    {
    $output .= $indent . '<li id="item_'.$item->ID.'"><a href="#" class="'.strtolower($linkName).'" data-filter=".'.strtolower($linkName).'">'.$linkName.'</a>';
    }
    

    similarly do the same for last link

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题