个性化阅读
专注于IT技术分析

如何在侧边栏小部件的ul和childs li中添加类-WordPress

这是我在右侧栏中注册菜单的方式:

if(function_exists('register_sidebar')){
  register_sidebar(array(
            'name'=>'sidebar_default', 'before_widget' => '<div class="panel panel-info">', 'after_widget' => '</div>', 'before_title' => '<div class="panel-heading"><h4>', 'after_title' => '</h4></div>'
        ));
 }

这是输出:

<div class="panel panel-info">
   <div class="panel-heading">
      <h4>Title</h4>
   </div>
<div class="menu-openings-menu-container">
    <ul id="menu-openings-menu" class="menu">
       <li id="" class="menu-item-object-page menu-item-381"><a href="">Software</a></li>
       <li id="" class="menu-item-object-page menu-item-382"><a href="">Software</a></li>
       <li id="" class="menu-item-object-page menu-item-383"><a href="">Software</a></li>
       <li id="" class="menu-item-object-page menu-item-384"><a href="">Software</a></li>
       <li id="" class="menu-item-object-page menu-item-385"><a href="">Software</a></li>
    </ul>
</div>
</div>

这是它需要如何输出才能使用Twitter Bootstrap列表样式的样式:

<ul class="list-group">
  <li class="list-group-item">Cras justo odio</li>
  <li class="list-group-item">Dapibus ac facilisis in</li>
  <li class="list-group-item">Morbi leo risus</li>
  <li class="list-group-item">Porta ac consectetur ac</li>
  <li class="list-group-item">Vestibulum at eros</li>
</ul>

我感谢所有建议。谢谢。

输出如下
源代码

#1


根据WordPress函数参考, 你可以在传递的选项中添加一个’class’=>’list-group’属性, 如下所示:

if(function_exists('register_sidebar')){
    register_sidebar(array(
        'name'=>'sidebar_default', 'before_widget' => '<div class="panel panel-info">', 'after_widget' => '</div>', 'before_title' => '<div class="panel-heading"><h4>', 'after_title' => '</h4></div>', 'class' => 'list-group'
    ));
}

这应该设置ul的类。我不确定是否也可以为单个li设置类, 但是可以通过ul访问这些类。

(css中的ul.list-group li)


#2


这仅适用于后端:(

    class - CSS class to assign to the Sidebar in the Appearance -> Widget admin page. This class will only appear in the source of the WordPress Widget admin page. It will not be included in the frontend of your website. Note: The value "sidebar" will be prepended to the class value. For example, a class of "tal" will result in a class value of "sidebar-tal". (default: empty).
before_widget - HTML to place before every widget(default: '<li id="%1$s" class="widget %2$s">') Note: uses sprintf for variable substitution
赞(0) 打赏
未经允许不得转载:srcmini » 如何在侧边栏小部件的ul和childs li中添加类-WordPress
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

微信扫一扫打赏