【问题标题】:Add span in wordpress menu在 wordpress 菜单中添加跨度
【发布时间】:2011-12-26 09:04:38
【问题描述】:

我想在 wordpress 菜单中的 <a> 标记之后添加一个 <span>,使其看起来像这样

<li class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-4 current_page_item menu-item-13">
<a href="http://wordpress.org/"><span>Home</span></a>
</li>

任何帮助和建议都将不胜感激。

【问题讨论】:

    标签: html wordpress markup


    【解决方案1】:

    嘿,谢谢你的回复,但我明白了。应该是这样的

    <?php wp_nav_menu( array( 'theme_location' => 'primary', 'link_before' => '<span>','link_after'=>'</span>' ) ); ?> 
    

    【讨论】:

      【解决方案2】:

      它在以下文件中:

      /wp-includes/nav-menu-template.php

      html 输出从第 82 行开始

      让我们好点,这是代码,将第 82 行替换为第 109 行:

          $output .= $indent . '<li' . $id . $value . $class_names .'>';
      
          $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
          $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
          $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
          $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
      
          $item_output = $args->before;
          $item_output .= '<a'. $attributes .'><span>';
          $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
          $item_output .= '</span></a>';
          $item_output .= $args->after;
      
          $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
      }
      
      /**
       * @see Walker::end_el()
       * @since 3.0.0
       *
       * @param string $output Passed by reference. Used to append additional content.
       * @param object $item Page data object. Not used.
       * @param int $depth Depth of page. Not Used.
       */
      function end_el(&$output, $item, $depth) {
          $output .= "</li>\n";
      }
      

      }

      【讨论】:

      • 您好,谢谢您的回复,但我明白了。应该是这样 'primary', 'link_before' => '','link_after'=>'' ) ); ?>
      • 另外,你不应该像那样编辑核心 WordPress 文件。如果您进行自动更新,您的所有更改都将丢失,并可能破坏网站。
      猜你喜欢
      • 2012-02-12
      • 1970-01-01
      • 2015-10-13
      • 2021-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多