下午早些时候,我曾要求解决如何在 Wordpress 的不同类别页面上回显不同的侧边栏的解决方案。现在我面临的问题是所有类别页面的侧边栏下都显示一个连续的“1”。但是,当我切换回在所有类别页面上仅显示一个侧边栏的旧代码时,这并没有发生。这是最初在 sidebar.php 文件中的代码,它在所有页面上只回显一个侧边栏:
<?php if ( is_active_sidebar( 'main_sidebar' ) ) : ?>
<div id="main_sidebar" class="widget-area">
<?php dynamic_sidebar( 'main_sidebar' ); ?>
</div><!-- #first_sidebar .widget-area -->
<?php endif; ?>
这是我放在 sidebar.php 文件中的修改后的代码,它在不同的类别页面上呼应不同的侧边栏:
<?php if ( is_active_sidebar( "main_sidebar" ) ) : ?>
<div id="main_sidebar" class="widget-area">
<?php
if ( is_category( '7' )) {
echo dynamic_sidebar( 'category_fashion' );
}
elseif ( is_category( '1' )) {
echo dynamic_sidebar( 'category_music' );
}
elseif ( is_category( '5' )) {
echo dynamic_sidebar( 'category_tastemakers' );
}
elseif ( is_category( '11' )) {
echo dynamic_sidebar( 'category_film' );
}
elseif ( is_category( '9' )) {
echo dynamic_sidebar( 'category_model' );
}
elseif ( is_category( '6' )) {
echo dynamic_sidebar( 'category_sports' );
}
elseif ( is_category( '8' )) {
echo dynamic_sidebar( 'category_round' );
}
elseif ( is_category( '10' )) {
echo dynamic_sidebar( 'category_cool' );
}
else
{
echo dynamic_sidebar( 'main_sidebar' );
}
?>
</div><!-- #first_sidebar .widget-area -->
<?php endif; ?>
当我使用原始代码时,数字“1”不会出现在侧边栏下,但是当我切换到我修改过的代码时,数字“1”开始出现在所有页面的侧边栏下。通过访问此链接可以看到此行为:http: //ignoremusic.com/category/sports/
我还检查了 archive.php 文件以及 functions.php 文件,但似乎没有任何问题。这是我放在 functions.php 文件中用于注册侧边栏的部分代码:
/** SIDEBARS ******************************************************************/
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name'=>'sidebar home left',
'id' => 'homeleft_sidebar',
'description' => __( 'sidebar on homepage, left', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Tastemakers',
'id' => 'category_tastemakers',
'description' => __( 'sidebar on tastemakers category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Film',
'id' => 'category_film',
'description' => __( 'sidebar on film category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Fashion',
'id' => 'category_fashion',
'description' => __( 'sidebar on fashion category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Model Citizens',
'id' => 'category_model',
'description' => __( 'sidebar on model citizens category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Sports',
'id' => 'category_sports',
'description' => __( 'sidebar on sports category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Round Table',
'id' => 'category_round',
'description' => __( 'sidebar on round table category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Cool Stuff',
'id' => 'category_cool',
'description' => __( 'sidebar on cool stuff category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'Category: Music',
'id' => 'category_music',
'description' => __( 'sidebar on music category', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'sidebar home right',
'id' => 'homeright_sidebar',
'description' => __( 'sidebar on homepage, right', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'main sidebar',
'id' => 'main_sidebar',
'description' => __( 'main sidebar', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'tour dates sidebar',
'id' => 'tour_sidebar',
'description' => __( 'sidebar on tour dates page', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'contact sidebar',
'id' => 'contact_sidebar',
'description' => __( 'sidebar on contact page', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'sidebar footer 1',
'id' => 'sidebarf1',
'description' => __( 'first sidebar in footer', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'sidebar footer 2',
'id' => 'sidebarf2',
'description' => __( 'second sidebar in footer', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'sidebar footer 3',
'id' => 'sidebarf3',
'description' => __( 'third sidebar in footer', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
register_sidebar(array(
'name'=>'sidebar footer 4',
'id' => 'sidebarf4',
'description' => __( 'fourth sidebar in footer', 'gxg_textdomain' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>', ));
}
这是archives.php文件中的代码,它与侧边栏相呼应:
<div id="sidebar" class="grid_3">
<?php get_sidebar(); ?>
</div><!-- #sidebar-->
我尝试在互联网上搜索问题,但找不到任何东西,所以我期待收到你们的来信。谢谢你。