WordPress.org

Support

Support » How-To and Troubleshooting » Trying to get custom sidebar to work

Trying to get custom sidebar to work

  • Trying to get my custom sidebar to show up. It’s registered and showing up in my widget area. The code in my sidebar-children.php file is:

    <?php if ( function_exists (dynamic_sidebar('sidebar-children') ) ) : ?>
    <?php dynamic_sidebar ('sidebar-children'); ?>
    <?php siblings();?>
    <?php endif; ?>

    and the call in the template is:

    <?php if ( is_active_sidebar( 'sidebar-children' ) ) : ?>
    <?php dynamic_sidebar( 'sidebar-children' ); ?>

    What am I doing wrong? Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • Make sure the registered name in functions.php is sidebar-children.

    Then call in the template like this:

    <?php get_sidebar('children'); ?>

    More info: http://codex.wordpress.org/Customizing_Your_Sidebar

    Michael

    @alchymyth

    Forum Moderator

    review
    http://codex.wordpress.org/Widgetizing_Themes

    your usage of function_exists() is not correct.

    I have updated my code and it’s still not working. So frustrating because I don’t see the issue. Here is my updated code. Any ideas?

    functions.php:

    function siblings_widgets_init() {
    
    register_sidebar( array(
    'name' => 'Children-List',
    'id' => 'sidebar-children',
    'before_widget' => '<div id="%1$s" class="widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h2 class="someclass ">',
    'after_title' => '</h2>',
    ) );
    }
    add_action( 'widgets_init', 'siblings_widgets_init' );<code></code>
    
    <?php if ( !dynamic_sidebar('sidebar-children') ) : ?>'
    
    sidebar.php

    <?php siblings();?>
    <?php endif; ?>

    <?php endif; // end primary widget area ?>
    </div><!– #primary .widget-area –>

    and the call in the template:
    
    '<?php
    	if ( !dynamic_sidebar('sidebar-children') ) :
    	else :
    	?>
    	<?php endif; ?>

    Michael

    @alchymyth

    Forum Moderator

    your code got a bit mangled – please repost the three codes:

    the section in functions.php;
    the full code of sidebar-children.php;
    and the call for the sidebar in the template.

    btw:
    what is siblings(); supposed to show?

    Hope this is better:
    functions.php:

    function siblings_widgets_init() {
    
    register_sidebar( array(
    'name' => 'Children-List',
    'id' => 'sidebar-children',
    'before_widget' => '<div id="%1$s" class="widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h2 class="someclass ">',
    'after_title' => '</h2>',
    ) );
    }
    add_action( 'widgets_init', 'siblings_widgets_init' );

    sidebar.php:

    <?php if ( !dynamic_sidebar('sidebar-children') ) : ?>'
    <?php siblings();?>
    <?php endif; ?>
    
    <?php endif; // end primary widget area ?>
    </div>

    and the call in the template:

    <?php
    	if ( !dynamic_sidebar('sidebar-children') ) :
    	else :
    	?>
    	<?php endif; ?>

    Siblings is just referring to a function that is listing children in my sidebar

    Michael

    @alchymyth

    Forum Moderator

    if you drag a widget into the new ‘children-list’ widget area, does something show in your site when you use the template?

    into what template have you actualy added that code?

    what theme are you using?

    can you post a link to the page where you expect to see the new sidebar?

    no link, working locally. I’ve added it to page template. Working on a twentyten child.

    And yes I can get some of the standard widgets in like blogroll etc. I want to put in a siblings list. I have tested that function is working also, so the disconnect is in calling the specific sidebar. Do you see anything wrong there.

    I appreciate your help.

    Michael

    @alchymyth

    Forum Moderator

    the siblings list siblings() will not get called if there are widgets in the widget area.

    you will need to move to the outside of the if statement;

    change from:

    <?php if ( !dynamic_sidebar('sidebar-children') ) : ?>'
    <?php siblings();?>
    <?php endif; ?>

    to:

    <?php if ( !dynamic_sidebar('sidebar-children') ) : ?>'
    <?php endif; ?>
    <?php siblings();?>

    or:

    <?php siblings();?>
    <?php if ( !dynamic_sidebar('sidebar-children') ) : ?>'
    <?php endif; ?>

    if you have added the new sidebar code into sidebar.php of your theme, please post the full code of sidebar.php

    also, if you have time, review http://codex.wordpress.org/Theme_Development
    and
    http://codex.wordpress.org/Function_Reference/dynamic_sidebar

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Trying to get custom sidebar to work’ is closed to new replies.
Skip to toolbar