Community Forums › Forums › Archived Forums › Design Tips and Tricks › Make the sidebar automatically generated by category
- This topic has 8 replies, 3 voices, and was last updated 9 years, 1 month ago by aaron_velloe.
-
AuthorPosts
-
January 9, 2015 at 2:18 pm #136778aaron_velloeMember
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.comJanuary 10, 2015 at 9:31 am #136877JanHoekParticipantYou 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 #136930Ren VenturaMemberSo 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 #137218aaron_velloeMemberWow, 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 #137220Ren VenturaMemberYou'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 #137228aaron_velloeMemberI 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 #137229Ren VenturaMemberAh, 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 #137243aaron_velloeMemberThe code works perfectly.
Thank you for all your patience, it's greatly appreciated!March 4, 2015 at 11:24 am #143196aaron_velloeMemberIs there a way to set it up so that my blog roll page to have it's own individual sidebar?
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.