Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'1' digit appearing under sidebar of wordpress website

Earlier in the afternoon, I had asked for a solution on how to echo different sidebars on different category pages of Wordpress which was solved. Now the problem which I am facing is that there's a continuous '1' being displayed under the sidebar on all the category pages. However, this isn't happening when I switch back to the old code which was displaying only one sidebar on all the category pages. Here's the code which was originally inside the sidebar.php file and which was echoing only one sidebar on all the pages:

<?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; ?>

And this is the modified code which I have put inside the sidebar.php file which is echoing different sidebars on different category pages:

<?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; ?>

When I use the original code, the number '1' doesn't appear under the sidebar but when I switch to the code which I've modified, the number '1' starts to appear under the sidebar on all the pages. This behavior can be seen by going to this link: http://ignoremusic.com/category/sports/

I have also checked the archive.php file as well as the functions.php file but nothing seems to be wrong. Here's the part of the code which I've put inside the functions.php file to register the sidebars:

/** 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>', ));
}

And this is the code inside the archives.php file which is echoing the sidebar:

<div id="sidebar" class="grid_3">
                    <?php get_sidebar(); ?>
            </div><!-- #sidebar-->

I tried searching for the problem on the internet but couldn't find anything so I look forward to hear from you guys. Thank you.

like image 370
Fahad Hasan Avatar asked Apr 02 '13 14:04

Fahad Hasan


2 Answers

According to https://codex.wordpress.org/Function_Reference/dynamic_sidebar it should be

dynamic_sidebar( 'category_fashion' );

instead of echo dynamic_sidebar( 'category_fashion' );
The function probably returns true; echo takes a string; true->string=1, therefore the additional 1.

like image 52
VolkerK Avatar answered Nov 07 '22 01:11

VolkerK


Superfluous echo, caused by confusion, caused by silly Wordpress functions that print things rather than returning them.

In your case, the following is at fault:

<?php echo dynamic_sidebar( 'category_fashion' ); ?>

Contrast with your earlier and correct usage:

<?php dynamic_sidebar( 'main_sidebar' ); ?>
like image 30
Lightness Races in Orbit Avatar answered Nov 06 '22 23:11

Lightness Races in Orbit