• Resolved claudchan

    (@claudchan)


    Hi all,

    I need a help here. I am using twentyeleven theme as my wordpress’s child theme. How to add more footer area widget without modifying the twentyeleven theme folder?

    Currently everything works great with step by step and others tutorial on how to add more footer area widget but one last thing I couldn’t get it is the class ( twentyeleven_footer_sidebar_class() ).

    Below is my codes in my child theme folder:
    1.) functions.php
    2.) sidebar-footer.php

    ==========================================
    1.) functions.php
    ==========================================

    I copy the function (twentyeleven_widgets_init()) from original twentyeleven functions.php into my child theme and I rename it to “twentyeleven_child_widgets_init”.

    CODES:

    function twentyeleven_child_widgets_init() {
    
    	/* ...original codes here... */
    
    	/* add codes start here */
    
    	register_sidebar( array(
    		'name' => __( 'Footer Area Four', 'twentyeleven' ),
    		'id' => 'sidebar-6',
    		'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ),
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget' => "</aside>",
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );
    
    	/* add codes end here */
    
    }
    add_action( 'widgets_init', 'twentyeleven_child_widgets_init' );

    This codes above runs fine.

    Next:

    I copy the function (twentyeleven_footer_sidebar_class()) from original twentyeleven functions.php into my child theme and I rename it to “twentyeleven_child_footer_sidebar_class”.

    CODES:

    function twentyeleven_child_footer_sidebar_class() {
    	$count = 0;
    
    	if ( is_active_sidebar( 'sidebar-3' ) )
    		$count++;
    
    	if ( is_active_sidebar( 'sidebar-4' ) )
    		$count++;
    
    	if ( is_active_sidebar( 'sidebar-5' ) )
    		$count++;
    
    	if ( is_active_sidebar( 'sidebar-6' ) )
    		$count++;
    
    	$class = '';
    
    	switch ( $count ) {
    		case '1':
    			$class = 'one';
    			break;
    		case '2':
    			$class = 'two';
    			break;
    		case '3':
    			$class = 'three';
    			break;
    		case '3':
    			$class = 'four';
    			break;
    	}
    
    	if ( $class )
    		echo 'class="' . $class . '"';
    }

    This codes above runs fine but not the class “four”. I unable to get the class “four”.

    ==========================================
    2.) sidebar-footer.php
    ==========================================

    I copy this file (sidebar-footer.php) from original twentyeleven and put into my child theme folder. I add new codes accordingly and rename “twentyeleven_footer_sidebar_class()” to “twentyeleven_child_footer_sidebar_class()”.

    CODES:

    <?php
    	/* The footer widget area is triggered if any of the areas
    	 * have widgets. So let's check that first.
    	 *
    	 * If none of the sidebars have widgets, then let's bail early.
    	 */
    	if (   ! is_active_sidebar( 'sidebar-3'  )
    		&& ! is_active_sidebar( 'sidebar-4' )
    		&& ! is_active_sidebar( 'sidebar-5'  )
    		&& ! is_active_sidebar( 'sidebar-6'  )
    	)
    		return;
    	// If we get this far, we have widgets. Let do this.
    ?>
    <div id="supplementary" <?php twentyeleven_child_footer_sidebar_class(); ?>>
    	<?php if ( is_active_sidebar( 'sidebar-3' ) ) : ?>
    	<div id="first" class="widget-area" role="complementary">
    		<?php dynamic_sidebar( 'sidebar-3' ); ?>
    	</div><!-- #first .widget-area -->
    	<?php endif; ?>
    
    	<?php if ( is_active_sidebar( 'sidebar-4' ) ) : ?>
    	<div id="second" class="widget-area" role="complementary">
    		<?php dynamic_sidebar( 'sidebar-4' ); ?>
    	</div><!-- #second .widget-area -->
    	<?php endif; ?>
    
    	<?php if ( is_active_sidebar( 'sidebar-5' ) ) : ?>
    	<div id="third" class="widget-area" role="complementary">
    		<?php dynamic_sidebar( 'sidebar-5' ); ?>
    	</div><!-- #third .widget-area -->
    	<?php endif; ?>
    
    	<?php if ( is_active_sidebar( 'sidebar-6' ) ) : ?>
    	<div id="fourth" class="widget-area" role="complementary">
    		<?php dynamic_sidebar( 'sidebar-6' ); ?>
    	</div><!-- #third .widget-area -->
    	<?php endif; ?>
    </div><!-- #supplementary -->

    Please help. Many thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • in you twentyeleven_child_footer_sidebar_class(999999) function

    first of all plz check your code

    function twentyeleven_child_footer_sidebar_class() {
    	$count = 0;
    
    	if ( is_active_sidebar( 'sidebar-3' ) )
    		$count++;
    
    	if ( is_active_sidebar( 'sidebar-4' ) )
    		$count++;
    
    	if ( is_active_sidebar( 'sidebar-5' ) )
    		$count++;
    
    	if ( is_active_sidebar( 'sidebar-6' ) )
    		$count++;
    
    	$class = '';
    
    	switch ( $count ) {
    		case '1':
    			$class = 'one';
    			break;
    		case '2':
    			$class = 'two';
    			break;
    		case '3':
    			$class = 'three';
    			break;
    		case '3':
    			$class = 'four';
    			break;
    	}
    
    	if ( $class )
    		echo 'class="' . $class . '"';
    }

    plz check your case.. there are case ‘3’. duplicate.

    try out this.
    hope it works well for you. ??

    Thread Starter claudchan

    (@claudchan)

    Oh no!
    Is my eye problem. I didn’t see it with my own eyes.

    Thank you so much!

    LOL.. ??

    switch ( $count ) {
    		case '1':
    			$class = 'one';
    			break;
    		case '2':
    			$class = 'two';
    			break;
            ----->  case '3':
    			$class = 'three';
    			break;
    	-----> case '3':
    			$class = 'four';
    			break;
    	}

    CHECK THE BOLD ARROW…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘twentyeleven (child theme) – how to add more footer area widget?’ is closed to new replies.