【发布时间】:2015-04-22 00:05:08
【问题描述】:
我正在尝试在 wordpress 菜单中的每个链接之后添加顺序编号。它们应该在标签中并作为文本。所以我可以设计风格。
在下面尝试了这个,但由于它的 CSS,我无法设置这些数字的样式。
How to add sequential numbering for wordpress menu
我对JS一无所知。所以我在 navwalker.php 中做了这个
if(! empty( $item->attr_title )){
$item_output .= '<a'. $attributes .'><i class="' . esc_attr( $item->attr_title ) . '"></i> ';
} else {
$item_output .= '<a'. $attributes .'>';
}
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= ($args->has_children && $depth == 0) ? ' <span class="caret"></span></a>' : '</a>';
$item_output .= $args->after . '<span class="navnum">' . str_pad(esc_attr( $item->menu_order ), 2, "0", STR_PAD_LEFT) . '.</span>';
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
而且它有效。 唯一的问题是它在可折叠菜单中计算子菜单(子菜单),因此它会创建如下内容:
01
03
04
07
08
知道如何只给父母编号吗?
(如果解决方案是 JS,如果你解释得很简单,我将不胜感激)
【问题讨论】: