Black Friday Sale! Get up to $40 off GP Premium!Learn more

[Resolved] Different sidebars for posts and pages

Home Forums Support Different sidebars for posts and pages

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #493915
    Joni

    The answers I have found when searching the forum aren’t what I had in mind. I thought the plugin Custom Sidebars would do what I want, but it does not.

    I would like to be able to have the site display one suite of widgets on the RIGHT sidebar if it is a page; else display another suite of widgets, again on the RIGHT, on all blog posts, categories, archives, whatnot.

    Right now, the stopgap measure, which I am NOT thrilled with, is using the right sidebar for pages and the left sidebar for blog stuff. This flip-flopping from left to right is annoying to users at the least.

    Is there a way to code for a Page sidebar and a Blog sidebar in functions.php and then load up whichever sidebar with the widgets desired? I would b e happy to pay for some help with this or donate to further GP development. That’s how important this issue is to me.

    The site in its current iteration is here:
    https://idylwood.org

    Thanks!

    GeneratePress 2.0.2
    GP Premium 1.5.6
    #494004
    Leo
    Staff
    Customer Support

    Hi there,

    Have you tried this one? https://en-ca.wordpress.org/plugins/content-aware-sidebars/

    It’s the one we’ve been recommending.

    #494021
    Joni

    That is the first one I tried and it won’t allow a different widget on the same side (in my case, the right side). So that didn’t work. It seemed, in theory, that Custom Sidebar widget would work, it allows you to specify clearly what post types go where, but it failed too.

    I just want to be able to have one right hand sidebar for pages and another right hand sidebar for blog stuff. I’ve coded that into functions files before, but cannot seem to get it to work with GP.

    My point being, I shouldn’t have to use a plugin, I should be able to plop some code into the functions.php file. I’ve tried several plugins and they simply won’t allow the right handed sidebar to be occupied by more than one suite of widgets. I think that is a GP limitation; it certainly isn’t a limitation in WordPress.

    #494035
    Tom
    Lead Developer
    Lead Developer

    It’s actually the way WordPress handles widgets – they’re meant to be global unless you register a completely new sidebar/widget area for every single page. You’ll notice the exact same experience using any theme – even the core Twenty-whatever themes released by WordPress.

    Content Aware Sidebars should be exactly what you’re looking for actually, it’s just a little confusing to get started.

    First, you would create a new custom sidebar – the one for pages for example: https://dev.institute/docs/content-aware-sidebars/getting-started/create-sidebar/

    Your target sidebar would be the “Right Sidebar”.

    Then apply it using the conditions option – in your case it would be all pages. Check the second section here: https://dev.institute/docs/content-aware-sidebars/getting-started/display-sidebar-simple/

    There’s tons of other plugins as well for this. This one has been around for a long time, and has a more simple UI: https://en-ca.wordpress.org/plugins/widget-context/

    It would be nice not to have to use a plugin for this, unfortunately WordPress simply doesn’t have that kind of functionality baked in. That’s why so many different plugins exist for it.

    Hope this helps!

    #494043
    Joni

    I will try it again, but as I said before, It didn’t work. I’ve been working with awp since 2004. I know a little bit about how it operates. I’ve always been able to create as many widget areas as I want, I just call them in the template. Of course, that’s when you “roll your own.”

    Just for fun, here is the code I inserted into the functions.php file of the GP child theme:

    function page_widgets_init() {
    
    	register_sidebar( array(
    		'name'          => 'Page Sidebar',
    		'id'            => 'page_sidebar',
    		'before_widget' => '<div>',
    		'after_widget'  => '</div>',
    		'before_title'  => '<h2>',
    		'after_title'   => '</h2>',
    	) );
    
    }
    add_action( 'widgets_init', 'page_widgets_init' );

    And here is the portion of the page.php template that lives in the child theme directory: I modified only the line where I have **

    	<?php
    	/**
    	 * generate_after_primary_content_area hook.
    	 *
    	 * @since 2.0
    	 */
    	 do_action( 'generate_after_primary_content_area' );
    
    	 generate_construct_sidebars('page_sidebar');**
    
    get_footer();

    And the page sidebar widget area does appear, as expected, but the pages are having none of it. 🙂

    #494044
    Joni

    So I have targeted the right sidebar for pages. Now what happens when I want the blog stuff on the right? That is the limitation of every single stinking plugin I’ve tried. I should be able to modify the child theme’s page.php to add a custom sidebar. Which is what I was attempting to do above.

    #494045
    Tom
    Lead Developer
    Lead Developer

    Ah, I think you’re thinking about the dynamic_sidebar() function.

    You can definitely go that route with a child theme.

    Instead of the second snippet, add this file to your child theme named sidebar.php: https://gist.github.com/generatepress/2fc35877f91e54fe415eb34a4ddb452c

    You’ll see I just added a simple conditional in there to check if we’re on a page. If we are, it will display the sidebar you registered with your first snippet above.

    If not, it will do the regular logic.

    #494058
    Joni

    At long last. Squeeeee!!!!! But one final gotcha to change before things righted themselves. I had to go back into Customizations and change the blog sidebar presentation to content | sidebar. Changing it on the News Page (see screen dump) wasn’t enough.

    Content-aware sidebar plugin

    #494059
    Joni

    Resolved. Hitting the donate button now. 🙂

    #494060
    Tom
    Lead Developer
    Lead Developer

    Index pages in WP (like the blog page) ignore metabox options, so that’s likely why you had to do it in the Customizer.

    Glad you got it working 🙂

    #494061
    Joni

    Where is your donate link, Tom?

    #494062
    Tom
    Lead Developer
    Lead Developer
    #494064
    Joni

    Found it; thank you!!!!

    #494069
    Tom
    Lead Developer
    Lead Developer

    Wow, thank you so much! That’s super generous of you 🙂

    Really appreciate it! As always, let me know if you have any other questions.

    #494468
    Joni

    It’s the least I could do! You spent at least an hour of your time helping me; I know your time is more valuable than mine! 🙂

Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.