0

This is my function:

function ec_register_sidebars() { 
register_sidebars( 3, 
    array( 
    'name' => 'Sidebar %d', 
    'id' => "sidebar-$i", 
    'before_widget' => '<li id="%1$s" class="widget %2$s">', 
    'after_widget' => '</li>', 
    'before_title' => '', 
    'after_title' => '' 
    ) 
); 

This does not work:

<?php if ( is_active_sidebar( 'Sidebar 1' ) ) : ?> 
<?php dynamic_sidebar( 'Sidebar 1' ); ?> 
    <?php else : ?> 
    No primary sidebar content 
<?php endif; ?>

BUT if I change the *is_active_sidebar* to 'Sidebar 2' or 'Sidebar 3', it works. For example, this works:

<?php if ( is_active_sidebar( 'Sidebar 2' ) ) : ?> 
<?php dynamic_sidebar( 'Sidebar 1' ); ?> 
    <?php else : ?> 
    No primary sidebar content 
<?php endif; ?>

I don't understand why this is. Any ideas?

1

it looks like your name attribute is missing the sprintf aspect. that line should read

'name' => sprintf(__('Sidebar %d'), $i ),

otherwise %d doesn't reference $i at all. Also, it looks like you should be calling the sidebar id, not the name. The name is just for looks. For example, once the above is fixed, this coould work:

<?php dynamic_sidebar( 'sidebar-1' ); ?> 
2
  • It's still not working. Here is a url with a text file that comprises all the code involved: estevancarlos.kodingen.com/ecv7/ec_code.txt Here is an active page: estevancarlos.kodingen.com/ecv7/?projects=rada-2 – rpeg Jan 12 '12 at 20:31
  • 1
    You should not check the active sidebar by the index number, then activate it with the slug id. use one or the other. ie. <?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?> <?php dynamic_sidebar( 'sidebar-1' ); ?>i would simplify the whole thing. also, don't generate all three sidebars in that one loop. add the three individually without the variables and %1$s complexity. look in the twentyten or twentyeleven theme and just copy exactly how they do it and modify it for your own. – dwenaus Jan 12 '12 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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