Site logo

Archived topic

Create a custom sidebar for archives pages

5 replies · Started by Hilton on December 4, 2019

Viewing posts 1–6 of 6

Hi,

I'd like to know how can I create a new sidebar to use only in archives pages.

Thanks

Hi Leo,

I don't want to install a plugin.

Then unfortunately you will need a custom solution.

That plugin is what we always suggest for requests like this.

I was thinking about doing the following:

Register a new sidebar:

if ( function_exists('register_sidebar') ) {
	register_sidebar(array(
		'name' => 'New Sidebar',
		'id' => 'new-sidebar',
		'description' => 'New Sidebar',
		'before_widget' => '<li id="%1$s">',
		'after_widget' => '</li>',
		'before_title' => '<h2>',
		'after_title' => '</h2>',
	));
}

2. Duplicate archive.php and rename to category.php.

3. Substitute generate_construct_sidebars(); for the following:

<?php if ( is_active_sidebar( 'new-sidebar' ) ) : ?>
    <div class="sidebar new-sidebar">
        <?php dynamic_sidebar( 'new-sidebar' ); ?>
    </div>
<?php endif; ?>

Do you think that will work?

Feel free to give it a shot.

Using the plugin might be an easier solution. Have you tried it?

It might not impact your site speed at all.

This archived topic is closed to new replies.