Support » Themes and Templates » Easily add widget areas to theme / template like Blogger (blogspot)

Viewing 3 replies - 1 through 3 (of 3 total)
  • Ok,
    There are many themes with different sidebar and widget layouts out there, this gives WordPress theme designers the ability to create and control the way they want the theme to show.

    It might be that the theme you like does not have the widget areas you want, so the options are to change the theme, or get “under the hood!”

    An extra Widget Area can be done really easy, a little code in functions.php, a new template part file and a modification to the template file or header.php

    If you have a spare widget area that you know you will not be using, wrap it in a template part and call it in the template.

    What theme do you have installed?

    Based on a Twenty Eleven Child Theme
    Adding a new Widget Area, wrapping it in a Template Part, and calling the file

    functions.php

    add_action( 'after_setup_theme', 'child_theme_setup' );
    
    if ( !function_exists( 'child_theme_setup' ) ):
    function child_theme_setup() {
    
    	register_sidebar( array(
    		'name' => __( 'Horizontal Widget Area One', 'twentyeleven' ),
    		'id' => 'horizontal-1',
    		'description' => __( 'An optional horizontal widget area', 'twentyeleven' ),
    	) );
    
    }
    endif;

    The Template Part:
    A new file horizontal-1.php

    <?php if ( is_active_sidebar( 'horizontal-1' ) ) : ?>
    	<div class="widget-area horizontal-1" role="complementary">
    		<?php dynamic_sidebar( 'horizontal-1' ); ?>
    	</div><!-- .widget-area -->
    <?php endif; ?>

    Then copy the page or header.php from the parent to the child theme
    and where you want the the new widget area to show.

    <?php get_template_part('horizontal','1'); ?>

    Adding the class horizontal-1 means you can style it in style.css

    .horizontal-1 {
        list-style: none;
        text-align: center;
    }

    HTH

    David

    THANK YOU!!!!!!!!!!!

    Just marked the topic as resolved

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Easily add widget areas to theme / template like Blogger (blogspot)’ is closed to new replies.