Note : Please note that I create this theme to re-sell, so I need little bit good way to add it.
这是我在右侧边栏上注册菜单的方式:
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引导列表样式:
<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>
我感谢所有建议。谢谢
SO网友:Johansson
如果你打算像评论中所说的那样销售你的主题,并且你想对导航菜单进行重大更改以在小部件中使用,我不确定创建一个助行器是否是解决方案。
相反,我建议使用小部件或短代码来进一步使用。下面是一个基本示例,使用wp_get_nav_menu_items()
:
add_shortcode(\'my-nav-menu\',\'my_nav_menu_callback\');
function my_nav_menu_callback($atts){
$atts = shortcode_atts(
array(
\'location\' => \'\',
),
$atts,
\'\'
);
// Get the menu by its theme location
$menu = get_term( $locations[$atts[\'location\']], \'nav_menu\' );
$menu_items = wp_get_nav_menu_items($menu->term_id);
// Run a loop and output the menu
$menu_list = \'<ul class="list-group">\';
foreach( $menu_items as $menu_item ) {
if( $menu_item->menu_item_parent == 0 ) {
$parent = $menu_item->ID;
$menu_array = array();
foreach( $menu_items as $submenu ) {
if( $submenu->menu_item_parent == $parent ) {
$bool = true;
$menu_array[] =\'<li class="list-group-item">\'.$submenu->title.\'</li>\';
}
}
if( $bool == true && count( $menu_array ) > 0 ) {
$menu_list .= \'<li class="list-group-item">\'.$menu_item->title.\'</li>\';
} else {
$menu_list .= \'<li class="list-group-item">\' . $menu_item->title . \'</li>\';
}
}
}
$menu_list .=\'</ul>\';
return $menu_list;
}
现在,您可以使用访问菜单
[my-nav-menu location=\'menu-location]
在内容或任何文本小部件中。
确保首先通过使用以下命令启用对在文本小部件中使用短代码的支持:
add_filter(\'widget_text\',\'do_shortcode\');
SO网友:Arthur Ronconi
您可以使用dynamic_sidebar_params
过滤器:
function dynamic_sidebar_before_filter ($params) {
$params[0][\'before_widget\'] = str_replace(\'class="widget-container\', \'class="widget-container w3-white w3-margin-bottom w3-card\', $params[0][\'before_widget\']);
$params[0][\'before_title\'] = str_replace(\'class="widget-title\', \'class="widget-title\', $params[0][\'before_title\']);
return $params;
}
add_action(\'dynamic_sidebar_params\', \'dynamic_sidebar_before_filter\');