910 VIEWS

WordPress tricks #3:How to create additional sidebar in WordPress theme

September 23, 2015

additional sidebar 640x242

 

We all like WordPress themes. However, most of these themes have only one sidebar. What if you need one more sidebar? For example, you want to create different sidebars for different categories.

In this tutorial, I will show you how to add an additional sidebar in WordPress theme. I am assuming that you have some basic knowledge of HTML and PHP.

Firstly, you need to register a new sidebar in your functions.php file in your theme folder. If you cannot find this file, you have to create one. If you have to create this file on your own, just open your favorite text editor to start a new file. Put the following code into this new file (functions.php):

<?php
if (function_exists('register_sidebar')) {
    register_sidebar(array(
         'name' => 'Sidebar second',
         'id'   => 'sidebar-second',
         'description'   => 'This is the second siadebar.',
         'before_widget' => '<div id="%1$s" class="widget %2$s">',
         'after_widget' => '</div>',
         'before_title' => '<h2>',
         'after_title'   => '</h2>'
    ));
}

Secondly, you need to create the second sidebar (sidebar-second.php) in your theme folder. Put this code in this new file.

<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Sidebar second')) : else : ?>
<!-- All this stuff in here only shows up if you DON'T have any widgets active in this zone -->
<?php endif; ?>

Finally, you can call this second sidebar in your theme. For example, you want to put this second sidebar in your category Training. Then create a new php file with name of category-training (category-training.php) in your theme folder. Put the following code in the category-training.php file:

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

Now you have an additional sidebar for the category training. You also can add widgets from your WordPress Dashboard-Appearance-Widgets.

 

Yonge Chen

BY

Web Developer/Digital Marketer

As a Web Developer,  I plan, create and code web pages, applying both non-technical and technical skills to produce web applications that meet the customer's requirements.

As a digital marketing specialist, I am well versed in SEO, SEM, inbound marketing, content, social media, and heavily get involved with all sides of online marketing to help clients generate opportunities, drive sales, and build brand.

get our free ebook

free ebook download

conversion rate optimization

the way to increase your online sales!

download now

Download Free E-book

Conversion Rate Optimization – The Way to Increase Your Online Sales


Sign up to get instant access to my ultimate guide to successful Conversion Rate Optimization and keep updated on our actionable tips plus exclusive deals!