Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Disclaimer: I am brand spanking new to WP.

I am using the Starkers HTML5 framework theme. In the functions.php I see this code:

function starkers_widgets_init() {

  // Area 1, located at the top of the sidebar.
  register_sidebar( array(
    'name' => __( 'Primary Widget Area', 'starkers' ),
    'id' => 'primary-widget-area',
    'description' => __( 'The primary widget area', 'starkers' ),
    'before_widget' => '<li>',
    'after_widget' => '</li>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
  ) );

  // Area 3, located in the footer. Empty by default.
  register_sidebar( array(
    'name' => __( 'First Footer Widget Area', 'starkers' ),
    'id' => 'first-footer-widget-area',
    'description' => __( 'The first footer widget area', 'starkers' ),
    'before_widget' => '<li>',
    'after_widget' => '</li>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
  ) );

  // ... more calls to register_sidebar() ... 
}

And in footer.php I see this code:

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

I don't understand how get_sidebar() knows how to take that string argument and find the appropriate widgets that were defined by register_sidebar(). In the functions.php snippet I posted above. There isn't any mention of "footer" except for the name, id and description properties. But it would seem odd to me that get_sidebar() would search for 'footer' inside those properties.

Does this make sense what I am asking? Is there some missing piece?

The reasons I am asking is because - I would like to know more about the WP architecture - I would like to be able to define a custom widget area and know how to render it on a specific page.

Thanks a ton.

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

You just call get_sidebar() from index.php and it loads the theme file sidebar.php.

register_sidebar(), on the other hand, is used for widgets where plugins and such want to dynamically add content in your sidebar.php file if your theme supports it.

In your case, is there a file called sidebar-footer.php in your theme's directory?

share|improve this answer
    
Thanks. That's what I needed to know. –  jessegavin Aug 18 '10 at 19:24
add comment

I've never bothered with get_sidebar(). Instead I just use dynamic_sidebar(). You'd call it like this:

dynamic_sidebar('first-footer-widget-area');

And that takes care of the whole sidebar. No more file inclusions, no more cluttered theme folders. If I want to have 5 different sidebars, it doesn't add any files, only extra functions in functions.php.

share|improve this answer
    
In the case of Starkers, sidebar-footer.php conditionally calls dynamic_sidebar() for all the appropriate widget areas. –  Annika Backstrom Aug 18 '10 at 19:27
    
That may be true, but if you know the version you're running, there's no need to conditionally call it, and why run an include if you can just call the function directly? –  John P Bloch Aug 18 '10 at 19:30
    
That's also really good to know. Thanks John. –  jessegavin Aug 18 '10 at 19:31
add comment

get_sidebar('footer') attempts to load sidebar-footer.php from the active theme. Starkers does provide this file. Check starkers/sidebar-footer.php and things should become clear.

share|improve this answer
    
+1 for the specific answer about my theme. –  jessegavin Aug 18 '10 at 19:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.