我面临着边栏小部件的问题。我已经注册了侧栏并使用了wp默认侧栏,但它既不在其容器div中也不在未打印中before_widget
和after_widget
add_action( \'widgets_init\', \'my_sidebar_widget\' );
function my_sidebar_widget(){
register_sidebar( array(
\'name\' => __(\'Home Page Sidebar\', \'nefar\'),
\'id\' => \'sidebar-1\',
\'before_widget\' => \'<div class="sidebar-block">\',
\'before_widget\' => \'</div>\',
\'before_title\' => \'<h4 class="sidebar-heading">\',
\'after_title\' => \'</h4>\',
));
}
和索引。php代码在这里
<?php
get_header();
?>
<div class="container">
<div class="row">
<div class="col-md-8">
<?php
if(have_posts()){
while(have_posts()){
the_post();
?>
<h3><?php the_title(); ?></h3>
<?php
}
}
?>
</div>
<div class="col-md-4">
<?php
dynamic_sidebar(\'sidebar-1\');
?>
</div>
</div>
</div>
<?php
get_footer();
和输出页面上的源代码
<div class="container">
<div class="row">
<div class="col-md-8">
<h3>The 15 Secrets That You Shouldn’t Know About Toys.</h3>
<h3>eMusic’s owners believe they can convince users start buying songs again</h3>
<h3>Twitter invokes the allure of one of its biggest users for its billboard ads</h3>
<h3>Spring Asparagus with Creamy Burrata & Pesto</h3>
<h3>Falling Leaves: Endearing Portraits of a Grandmother, a Grandson</h3>
</div>
<div class="col-md-4">
</div><h4 class="sidebar-heading">Search</h4><form role="search" method="get" id="searchform" class="searchform" action="http://localhost/wordpress/">
<div>
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form></li>
</div>
</div>
我不知道小部件后面的是什么,小部件在外面col-md-4
SO网友:dheeraj Kumar
首先将此代码添加到函数中。php
register_sidebar(array(
\'name\' => __(\'Top Footer\', \'educate\'),
\'id\' => \'top-footer\',
\'description\' => __(\'Top Full width footer.\', \'educate\'),
\'before_widget\' => \'<div class="footer-widget %2$s" id="%1$s" >\',
\'after_widget\' => \'</div>\',
\'before_title\' => \'<h3 class="footer-widget-title">\',
\'after_title\' => \'</h3>\',
));
将此代码添加到要显示小部件的位置后
<?php if (is_active_sidebar(\'top-footer\')) {
if (is_active_sidebar(\'top-footer\')) {
echo \'<aside class="col-md-12 col-sm-6">\';
dynamic_sidebar(\'top-footer\');
echo \'</aside>\';
}
} ?>