简体   繁体   English

添加图标到 <li> 菜单

[英]Adding icon to <li> menu

i am working on a school project and I am stuck at a point where i want to put an image ( >><< ) inbetween <li> -tags. 我正在研究一个学校项目,我被困在一个我想把图像(>> <<)置于<li> -tags之间的地方。 Because it's a navigation in wordpress it's done in php. 因为它是wordpress中的导航,所以它是在php中完成的。

Here is what i have: 这是我有的:

img http://img825.imageshack.us/img825/253/screenshot20120529at305.png img http://img825.imageshack.us/img825/253/screenshot20120529at305.png

Here is what i want (look at the blue thingies in between the menu items): 这就是我想要的(看看菜单项之间的蓝色东西):

img http://img703.imageshack.us/img703/253/screenshot20120529at305.png img http://img703.imageshack.us/img703/253/screenshot20120529at305.png

I think this is the php where i need to put my image/menuitem.png.. but where? 我认为这是我需要把我的图像/ menuitem.png ..但在哪里? Help would very much be appreciated 非常感谢帮助

 function inkthemes_nav() { if (function_exists('wp_nav_menu')) wp_nav_menu(array('theme_location' => 'custom_menu', 'container_id' => 'menu', 'menu_class' => 'ddsmoothmenu', 

'fallback_cb' => 'inkthemes_nav_fallback')); 'fallback_cb'=>'inkthemes_nav_fallback')); else inkthemes_nav_fallback(); else inkthemes_nav_fallback(); } }

 function inkthemes_nav_fallback() { ?> <div id="menu"> <ul class="ddsmoothmenu"> <?php wp_list_pages('title_li=&show_home=1&sort_column=menu_order'); ?> </ul> </div> <?php } function inkthemes_home_nav_menu_items($items) { if (is_home()) { //home $homelink = '<li class="current_page_item">' . '<a href="' . home_url('/') . '">' . __('Home', 'themia') . '</a></li>'; } else { //niet home $homelink = '<li>' . '<a href="' . home_url('/') . '">' . __('Home', 'themia') . '</a></li>/>'; } $items = $homelink . $items; return $items; } 

Try to use a CSS-Only solution: 尝试使用仅CSS解决方案:

.ddsmoothmenu li {
  background: url('image/menuitem.png') no-repeat left center;
  padding-left:30px /* you have to adjust this manually */
}
.ddsmoothmenu li:first-child{
  background:none;
  padding-left:0;
}

You will have to add an image tag at both locations that say HERE, however that would also put an image behind the last item. 您必须在两个位置都添加一个图像标签,但是这也会在最后一个项目后面放置一个图像。

$homelink = '<li class="current_page_item">' . '<a href="' . home_url('/') . '">' . __('Home', 'themia') . '</a></li> HERE';
    } else {
     //niet home
 $homelink = '<li>' . '<a href="' . home_url('/') . '">' . __('Home', 'themia') . '</a></li>/> HERE';

Better would be to add it using css, something like: 更好的方法是使用css添加它,例如:

#menu li {
 padding-right: 30px;
 background: url('path/to/image') no-repeat right center;
}

#menu li:last-child {
 background: none;
}

See the css property list-style-image . 请参阅css属性list-style-image You may prevent this on the first one with the css class :first-child 您可以使用css类在第一个上阻止这种情况:first-child

Here as an example: 这里举个例子:

.ddsmoothmenu li {
    list-style-image: url('image/menuitem.png');
}
.ddsmoothmenu li:first-child{
    list-style-image:none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM