0

I'm currently using Wordpress theme for my website. Decide to create my own sidebar, but the styling of it must be remain the same one as original sidebar. I'm had create a new sidebar in functions.php using register_sidebar. How my theme create sidebar was just <?php get_sidebar(); ?> nothing else. In my theme folder, there is not extra sidebar php file created. I'm try to use <?php dynamic_sidebar( $index ); ?> but it does not works for me. I just want to add new widget to my second sidebar that I created and the style will be default.

Functions.php

if (function_exists('register_sidebar')) {
register_sidebar(array(
'name'=>'Sidebar-Aries',
'id' => 'sidebar-aries',
'description' =>'Display all the contents of sidebar at Aries page.',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));
}

Using dynamic sidebar,

<?php dynamic_sidebar('sidebar-aries'); ?>
  • There is nothing wrong with your code, that I can see. And a quick test indicates that it works. What is the question? Please elaborate. – s_ha_dum Feb 21 '14 at 4:19
  • Is your theme a custom built one or a child theme. – Pieter Goosen Feb 21 '14 at 5:24
0

Here's the way i would code it. Tested

Add to functions file

add_action( 'widgets_init', 'wpsites_add_widget' );

function wpsites_add_widget() {

register_sidebar(array(
'name'=>'Sidebar-Aries',
'id' => 'sidebar-aries',
'description' =>'Display all the contents of sidebar at Aries page.',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));
}

Or you could use this code in your template and change the classes to match your existing widget

Option 1 - Add to template

<?php if ( is_active_sidebar( 'sidebar-aries' ) ) : ?>
<ul id="sidebar">
    <?php dynamic_sidebar( 'sidebar-aries' ); ?>
</ul>
<?php endif; ?>

Option 2 - Add to template

You could also add a conditional tag to control which pages your widget outputs

<?php if ( is_active_sidebar( 'sidebar-aries' ) && is_conditional() ) : ?>
<ul id="sidebar">
    <?php dynamic_sidebar( 'sidebar-aries' ); ?>
</ul>
<?php endif; ?>

Replace is_conditional() with your conditional tag

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.