WordPress.org

Ready to get started?Download WordPress

Forums

Trying to get custom sidebar to work (10 posts)

  1. lee718
    Member
    Posted 2 years ago #

    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

  2. phe.le
    Member
    Posted 2 years ago #

    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

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

    your usage of function_exists() is not correct.

  4. lee718
    Member
    Posted 2 years ago #

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

  6. lee718
    Member
    Posted 2 years ago #

    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; ?>
  7. lee718
    Member
    Posted 2 years ago #

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

  8. 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?

  9. lee718
    Member
    Posted 2 years ago #

    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.

  10. 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

Topic Closed

This topic has been closed to new replies.

About this Topic