这是我的档案:
<?php
$defaults = array(
'theme_location' => '',
'menu' => '',
'container' => 'div',
'container_class' => true,
'container_id' => 'btn',
'menu_class' => true,
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '<li class="btn_bar"><img src="img/pic-btn_bar.jpg"/></li>',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul>%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $defaults );
?>
在这里,我插入class =“btn_bar”&gt;
<ul>
<li class="menu-item-xxx">ABC</li>
<li class="btn_bar"><img width="18" height="38" src="img/pic-btn_bar.jpg"></li>
<li class="menu-item-xxx">DEF</li>
<li class="btn_bar"><img width="18" height="38" src="img/pic-btn_bar.jpg"></li>
</ul>
我想将代码放在菜单的第一个或最后一个菜单中。请帮帮我
答案 0 :(得分:0)
听起来你可以用CSS而不是PHP / HTML来做这件事。使用CSS,您可以定位特定的菜单项,并使用伪后插入图像。
.menu-item-82:after {
content: " ";
position: relative;
background: url(images/nav-image.png) -1px -32px #ddd;
display: block;
height: 25px;
width: 25px;
}
答案 1 :(得分:0)
另一个简单的css hack,只要你确定了你的菜单项id
#menu-item-1244 .delimiter {display:none;}
答案 2 :(得分:0)
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#doctype li:first").after("<li class='btn_bar'><img src='http://i.stack.imgur.com/VNk7r.jpg?s=24&g=1'/></li>");
jQuery("#doctype li:last").after("<li class='btn_bar'><img src='http://i.stack.imgur.com/VNk7r.jpg?s=24&g=1'/></li>");
});
</script>
<?php
$defaults = array(
'theme_location' => 'primary',
'menu' => 'Menu 1',
'container' => 'div',
'container_class' => '',
'container_id' => 'doctype',
'menu_class' => '',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul class="filter">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $defaults );
?>