• Resolved milkyco

    (@milkyco)


    Hi Tomas, I’ve been trying to edit the child theme so that I can use sidebar-2 and sidebar-3 on all pages if I want, not just with the front page template. I’ve sort of got it working by pretty much replacing the contents of sidebar.php with the contents of sidebar-front.php and editing it slightly.

    Below is what I ended up with – I added sidebar-1 as well just to try it but I don’t know if I will use it as well, and I changed the ids. It seems to work fine but only if I add a widget to the Main (sidebar-1). If the Main widget area is empty nothing appears in the sidebar area at all, is that correct? If so, not a problem I can add an empty text widget and stop it displaying.

    I also didn’t know whether I should add sidebar-1 to the first if along with 2 and 3?

    I tried that and it did not fix the non display issue.

    Or am I doing this all wrong? Quite possibly :-).

    Hope you can help, David

    <?php
    
    if ( ! is_active_sidebar( 'sidebar-2' ) && ! is_active_sidebar( 'sidebar-3' ) )
    	return;
    
    // If we get this far, we have widgets. Let do this.
    ?>
    <div id="secondary" class="widget-area" role="complementary">
    	<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
    	<div id="main_wrapper">
    		<?php dynamic_sidebar( 'sidebar-1' ); ?>
    	</div><!-- .first -->
    	<?php endif; ?>
    
    	<?php if ( is_active_sidebar( 'sidebar-2' ) ) : ?>
    	<div id="sidebar_wrapper">
    		<?php dynamic_sidebar( 'sidebar-2' ); ?>
    	</div><!-- .first -->
    	<?php endif; ?>
    
    	<?php if ( is_active_sidebar( 'sidebar-3' ) ) : ?>
    	<div id="sticky_sidebar_wrapper">
    		<?php dynamic_sidebar( 'sidebar-3' ); ?>
    	</div><!-- .second -->
    	<?php endif; ?>
    </div><!-- #secondary -->
Viewing 7 replies - 1 through 7 (of 7 total)
  • Theme Author Tomas Mackevicius

    (@tomasm)

    Hi, David, you’re right – widget area is not displayed if it’s empty. In some cases it is beneficial – very easy to turn the widget area off.

    If you want it to be constantly on, you can try to remove the IF is_active_sidebar( 'sidebar-1' ).

    Thread Starter milkyco

    (@milkyco)

    Hi Tomas, thank you for the speedy reply as always.

    OK great, thank you.

    I tried removing the following line which removes the Main sidebar-1 from the page, but if the Main Sidebar-1 widget is empty no sidebar appears at all. Is that correct?

    <?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
    	<div id="main_wrapper">
    		<?php dynamic_sidebar( 'sidebar-1' ); ?>
    	</div>
    <!-- .first -->
    	<?php endif; ?>

    Many thanks David

    Thread Starter milkyco

    (@milkyco)

    Sorry, that is not the case after all. If I remove that piece of code, sidebars 2 and 3 do appear, even if sidebar-1 is empty. I didn’t see them pushed down at the bottom of a long blog page. I see what happens now. The body becomes full width and pushes the sidebar down.

    body.full-width .site-content
    width: 100%

    rather than the normal .site-content
    float: left
    width: 73% (I changed it with your help previously)
    etc

    I don’t understand why the body becomes full width, can it be changed easily?

    All the best, David

    Theme Author Tomas Mackevicius

    (@tomasm)

    It looks that function tinyforge_body_class does it Section 6.0 in functions.php:

    function tinyforge_body_class( $classes ) {
    	$background_color = get_background_color();
    	$background_image = get_background_image();
    
    	// Using a full-width layout, when no active widgets in the sidebar or full-width template.
    	if ( ! is_active_sidebar( 'sidebar-1' )
    		|| is_page_template( 'page-templates/full-width.php' )
    		|| is_attachment() ) {
    		$classes[] = 'full-width';
    		}

    at this time it is not wrapped in “if function_exists”, but by doing it you could include whole function in child theme and remove that check for active sidebar-1.

    Thread Starter milkyco

    (@milkyco)

    OK, I see what you mean. I’m not going to try to edit the main functions.php so I’ll settle for the fact that it’s working as long as I have a widget in the main sidebar-1. I removed the sidebar-1 from the sidebar.php so now I have my two sidebar widgets working as I wanted.

    Many thanks, David

    Theme Author Tomas Mackevicius

    (@tomasm)

    For the v1.5.6 I will wrap this function in if function_exists and you will be able to replace it ??

    Thread Starter milkyco

    (@milkyco)

    Thank you Tomas.

    All the very best, David

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Using sidebar-2 and sidebar-3 on all pages?’ is closed to new replies.