This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Override sidebar layout column widths for homepage only

  • Creator
    Topic
  • #7785
    Danny
    Participant

    Hi
    Amazing I was following the docs and was able to get my default sidebar to different grid sizes..
    I now understand the grid better following the link to scaffolding.. For example grid 4 sidebar is about 300px wide than the grid 3 I was seeing is approx 220-19 or so. just by adding this from the dev docs..I get a site wide new smaller right sidebar. The add up to 12 is cool it really works..across all ways to manage the content..!

    function my_sidebar_layouts( $layouts ){
         
        $layouts['sidebar_right']['columns'] = array(
            'content'   => 'span9',
            'right'     => 'span3'
        );
         
        return $layouts;
     
    }
    add_filter( 'themeblvd_sidebar_layouts', 'my_sidebar_layouts' );

    OK so my goal is to call the smaller right sidebar on the home page only..
    or in a special builder layout..the sidebar doc is unclear sort of on how to add a new sidebar layout to all existing sidebar layouts at least to me. So I tried what I saw here in this post by doing this

    function my_sidebar_layout( $sidebar_layout ) {
     
       <strong> if( is_home() ) </strong>---this maybe wrong..Im not sure this -is_home is correct-
            $sidebar_layout = 'sidebar_right';
     
        return $sidebar_layout;
     
    }
    add_filter( 'themeblvd_sidebar_layout', 'my_sidebar_layout' );

    I than tried adding a new array to the helper and sidebar PHP files and to call it into the theme..Which worked except I
    was not able to display it correctly.. or it shows in admin as a selection but after that nothing..
    Following the dev docs is working but I submit this question as I am stuck here at this point and hope you can move me along..I am super impressed with how this system is working. I mean I never really got hooks that well..but I have applied them several times here and they work..which if your me is like HUGE..I mean come on compared the Theme blvd team I can’t even be the water boy..:)

Viewing 9 replies - 1 through 9 (of 9 total)
  • Author
    Replies
  • #7796
    Jason Bobich
    Keymaster

    Hello Dan,

    All right, so I read your question a few times now, and I think I understand what you’re going for and where you’re sort of misunderstanding in terms of general concept.

    But first, can you tell me how you’ve setup your homepage? Under Settings > Reading > Frontpage displays, what do you have set in your WordPress settings? — Knowing this, I can answer your question more specifically without further confusing anything.

    #7799
    Danny
    Participant

    Yes I am using the builder calling a layout using the reading setting of post..Not home page
    The builder is calling your standard sample layout for magazine.. so its a right sidebar and from there I am just experimenting with different elements.
    Adding remove parts. special widget areas..
    This sidebar example is to find out how to call a custom sidebar that has a custom grid applied to a builder layout…I did see that I could just create a new layout for the builder calling a new right sidebar..
    Regarding default sidebars layouts I would like to keep all the default sidebar layouts and add to that new sidebar layouts using smaller or larger grid sizes..I was able to adjust the current sidebar layouts but have not added one to it yet.
    I go thru all the files in jumpstart so I guess I am a bit all over the place..
    the bottom line is just- add new sidebar layout with a right sidebar of 3 instead of 4 and in that add a layout to the builder to call this or call this new sidebar in the builder when needed..I see in your dev docs how to do most of this and am going to try to call a custom layout to the builder..so any help in this direction is welcome..
    Thanks

    #7800
    Jason Bobich
    Keymaster

    You don’t want to add a new sidebar layout; that’s going to make things way more complicated than they need to be for what you’re doing.

    When you filter the widths of the columns, just check if it’s the homepage or not.

    function my_sidebar_layouts( $layouts ){
    	
    	// Modify widths of columns if this is the homepage.
    	if( is_home() ) {
    		$layouts['sidebar_right']['columns'] = array(
    			'content'	=> 'span9',
    			'right'		=> 'span3'
    		);
    	}
         
        return $layouts;
     
    }
    add_filter( 'themeblvd_sidebar_layouts', 'my_sidebar_layouts' );

    So basically what’s happening above is:
    1) You’re adding a filter to the array of sidebar layouts.
    2) If it’s the homepage, you’re modifying that array.
    3) Then you’re returning the sidebar layouts array, whether you modified it or not. If this isn’t the homepage, than it remains how it was before.

    #7803
    Danny
    Participant

    ok thanks I do not fully get filters yet..So this really helps..Jumpstart is my last stand with frameworks so Im determined to learn as much as your dev docs offer..I mean what with being able to use WP codex +bootstrap stuff..it has to end here..
    So I will always try to check your dev docs first and I really did not get to filters yet.. so it went swoosh! right over my head.:)
    Dan

    #7806
    Jason Bobich
    Keymaster

    Filters just give you a way to hook in and edit some variable that the theme is using.

    For example, say the framework had some function that does something with a variable, and you see it has a filter applied to it.

    function themeblvd_whatever(){
    	$text = apply_filters('themeblvd_whatever_text', 'Hello World');
    	echo $text;
    }

    This above function is going to output “Hello World” but it has a filter attached to that text in case you wanted to change it from your Child theme.

    This means you can use the filter to hook in at that spot and change the “Hello World” to something else. You can now setup a function where you take that $text variable and pass it through your own function, and “filter” it.

    So, in your Child theme, you’d do this:

    function my_whatever_text( $text ) {
    	$text = 'Something else';
    	return $text;
    }
    add_filter('themeblvd_whatever_text', 'my_whatever_text');

    $text is going into your function, you’re changing it, and then returning it back to the original spot the theme is using it — all before the theme continues using it.

    And now themeblvd_whatever() would output “Something else”.

    #7825
    Danny
    Participant

    wow! filters are way more powerful than I thought. Plus I actually get this..Plus after this conversation
    I was able to filter other sections and pages ..I swear if I just experiment with this and hooks I finally will see the power of what they really can do..I mean sure Ive done a few but this is a new world..
    Oh man thanks for holding my hand a bit..it will pay off..:)
    Dan

    #8965
    Danny
    Participant

    Hey one more question here.. if I want to filter the widths of a additional sidebar layout using the same basic function described here which is working.. say I add is_single() or is_page() than how would the rest of the function be defined so as not to cause a error which I get.. also for example if I just take the example from the dev docs it errors on layout already declared.

    function my_sidebar_layouts( $layouts ){
         
        $layouts['double_sidebar']['columns'] = array(
            'content'   => 'span8',
            'left'      => 'span2',
            'right'     => 'span2'
        );
         
        return $layouts;
     
    }
    add_filter( 'themeblvd_sidebar_layouts', 'my_sidebar_layouts' );

    Error already declared sidebar layout..cannot redeclare. Ok so if I change the function name ?
    Is it possible to only modify width for one custom sidebar layout?
    Of course this entire questions shows my obvious lack of comprehension so it goes with out saying..
    ๐Ÿ™‚

    #8968
    Jason Bobich
    Keymaster

    “my_sidebar_layouts” is just an example of what you could call the function. This function name can be anything in the world you want, but in PHP, you can’t have the same function name declared twice.

    So, this is why in the WordPress world, there is a lot of talk about “namespacing” and prefixing your function names. In all of these examples on the dev tutorials, I prefix the function names with “my” but in reality you should have some unique identifier that you’re using like “dan” for example.

    http://nacin.com/2010/05/11/in-wordpress-prefix-everything/

    For example —

    function dan_sidebar_layouts( $layouts ){
        // ...
        return $layouts;
    }
    add_filter( 'themeblvd_sidebar_layouts', 'dan_sidebar_layouts' );

    This should show you how the name of the function can be whatever you want. It doesn’t have to be what I’m writing in the tutorials. In this example, you need to use the filter “themeblvd_sidebar_layouts” but the name of your function can be anything you want as long as it’s not used anywhere else in WordPress, the theme, or your plugins.

    function dan_home_sidebar_layouts( $layouts ){
        // ...
        return $layouts;
    }
    add_filter( 'themeblvd_sidebar_layouts', 'dan_home_sidebar_layouts' );
    
    function dan_page_sidebar_layouts( $layouts ){
        // ...
        return $layouts;
    }
    add_filter( 'themeblvd_sidebar_layouts', 'dan_page_sidebar_layouts' );
    
    function dan_single_sidebar_layouts( $layouts ){
        // ...
        return $layouts;
    }
    add_filter( 'themeblvd_sidebar_layouts', 'dan_single_sidebar_layouts' );

    However, in this specific case, it doesn’t really make sense to have separate functions, unless you really want to for organization. You could just combine all of this in one function.

    function dan_sidebar_layouts( $layouts ){
    
    	if( is_home() ) {
    
    		$layouts['double_sidebar']['columns'] = array(
    			'content' 	=> 'span8',
    			'left' 		=> 'span2',
    			'right' 	=> 'span2'
    		);
    
    	} else if( is_single() ) {
    
    		$layouts['double_sidebar']['columns'] = array(
    			'content' 	=> 'span8',
    			'left'		=> 'span2',
    			'right' 	=> 'span2'
    		);
    
    	} else if( is_page() ) {
    
    		$layouts['double_sidebar']['columns'] = array(
    			'content' 	=> 'span8',
    			'left' 		=> 'span2',
    			'right' 	=> 'span2'
    		);
    
    	}
    
    	return $layouts;
    
    }
    add_filter( 'themeblvd_sidebar_layouts', 'dan_sidebar_layouts' );
    #9012
    Danny
    Participant

    Okay! thanks this works it was just the function name..Now I did try a different function name but you say “itโ€™s not used anywhere else in WordPress, the theme, or your plugins.”
    Thats the key..anywhere which I did not fully get until now..anywhere means anywhere..So thats interesting..I mean I put a name in a function and it mirrors a function somewhere in a plugin I get a error and wonder why? Ha! I’m not a hard case
    now I know a bit more.
    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.