• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Make the sidebar automatically generated by category

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Make the sidebar automatically generated by category

This topic is: not resolved

Tagged: category, Sidebar, snippet

  • This topic has 8 replies, 3 voices, and was last updated 10 years, 2 months ago by aaron_velloe.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • January 9, 2015 at 2:18 pm #136778
    aaron_velloe
    Member

    My wordpress site using the Genesis system is a blog with the Magazine Pro theme.

    I have the Genesis Simple Sidebars plugin installed, and it does a great job of allowing me to use a distinct sidebar for a particular category. As well, I can see that each article can be edited as well to use a specific sidebar.

    However, as the designer, I will not be writing or editing the articles, or doing much to this website once it's published. Is there a code snippet to add that will automatically include the corresponding sidebar based on the category the article is placed within?

    http://mtest.velloe.com
    January 10, 2015 at 9:31 am #136877
    JanHoek
    Participant

    You can take a look at this code from wpbeaches


    Hi, my name is Jan Hoek. Sure, they all say I have a big head, but I like to think it’s way too small for all my ideas.

    January 10, 2015 at 3:12 pm #136930
    Ren Ventura
    Member

    So you've created a sidebar for each category and want that sidebar to display only when a post from that category is being shown? I don't know if there's anything that's been written on this but the code to do so isn't too difficult. The first thing I would do is make sure your sidebars are named similar/identical to the categories. Make sure the naming convention you use is consistent (i.e. {category-slug}_sidebar). Then, you can use some code that gets the terms of a post, loops through each of them and checks to see if a sidebar exists using your naming convention.

    I wrote up some code to automatically register a sidebar for each category and output that sidebar when a post contains the category and there are widgets in the sidebar. If it's not exactly what you need, it should get you close.

    http://www.engagewp.com/create-sidebars-post-category-wordpress/


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    January 12, 2015 at 1:47 pm #137218
    aaron_velloe
    Member

    Wow, thank you very much for the code Ren Ventura!
    However, I'm embarrassed to admit, I'm not very experienced with php.

    Would it be possible to explain what I plug into where?

    Thank you again for your quick, and useful reply.

    January 12, 2015 at 2:03 pm #137220
    Ren Ventura
    Member

    You're very welcome!

    All that code can go in your functions.php. Just remember to NOT include the opening <?php tag.

    Also, if you include all of it, it will register sidebars for categories you have already registered sidebars for so you may need to do some cleanup if you want to use the code as-is.


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    January 12, 2015 at 2:31 pm #137228
    aaron_velloe
    Member

    I understood to put it into the functions.php, and leaving out the opening tag.

    What I mean is, do I need to inout the names of my sidebars or the categories themselves into the code somehwhere, or will the code you write up, make some sort of connection for me?

    January 12, 2015 at 2:43 pm #137229
    Ren Ventura
    Member

    Ah, no problem. The code automates everything so you don't need to modify it unless you want to change something. It grabs all of your categories and does its thing for all of them (no manual upkeep).


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    January 12, 2015 at 4:11 pm #137243
    aaron_velloe
    Member

    The code works perfectly.
    Thank you for all your patience, it's greatly appreciated!

    March 4, 2015 at 11:24 am #143196
    aaron_velloe
    Member

    Is there a way to set it up so that my blog roll page to have it's own individual sidebar?

  • Author
    Posts
Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble