[英]How to add class to <ul> and childs <li> of sidebar widget - Wordpress
[英]How to add wordpress widget widget to static Sidebar via code?
我正在制作一个WordPress网站,并有一个静态的侧边栏,我想知道如何在上述侧边栏中添加插件小部件。 这是我的侧边栏代码:
<div id="sidebar">
<div class="sidebar-entry sidebar-both">
<ul>
<?php the_widget( 'WP_Widget_Search' ); ?>
</ul>
</div>
<div class="sidebar-entry sidebar-left">
<h2> <?php _e('Categoies'); ?></h2>
<ul>
<?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
</ul>
</div>
<div class="sidebar-entry sidebar-right">
<h2> <?php _e('Archives'); ?></h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>
</div>
<div class="sidebar-entry sidebar-right">
<ul>
<?php the_widget( 'WP_Widget_Meta' ); ?>
</ul>
</div>
</div>
首先,您可以通过在functions.php文件中添加此代码来在主题中创建小部件区域
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name'=> 'Custom Sidebar',
'id' => 'custom_sidebar',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
现在您在appearance->widget
具有小部件区域“自定义侧栏”
现在,只需拖动该区域中的任何小部件,然后在您的自定义侧边栏中访问此小部件,请调用id为的dynamic_sidebar()
:
<?php dynamic_sidebar('custom_sidebar'); ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.