Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to build custom widget area for recipes above related posts
Tagged: After Entry, New Widget Area, related posts, text widget
- This topic has 8 replies, 3 voices, and was last updated 9 years, 11 months ago by
cookieandkate.
-
AuthorPosts
-
March 10, 2015 at 2:20 pm #143944
cookieandkate
MemberHi there,
I'm stumped and can't find any information on this subject. I would like to insert a text widget on all of my recipe posts (which fall under the "recipe" category). I want the widget to show up before my related posts widget, which positions itself after my post content and before my social media sharing options, so I don't think I can just target the after-entry area.
My related post section, titled "More recipes to enjoy," begins with the following div:
<div class="wp_rp_wrap wp_rp_plain" id="wp_rp_first">
You can view a typical recipe post of mine here: http://cookieandkate.com/2014/thai-curried-butternut-squash-soup/
Is there a way to insert a new widget area before that div on all recipe posts? I hope so! Any help would be MUCH appreciated.
Thank you,
http://cookieandkate.com
KateMarch 10, 2015 at 2:43 pm #143947WhiteleyDesigns
MemberMy approach, and there may be a better solution, would be to add the widget to all posts, hide it completely with CSS so it doesn't show up at all, the add some jQuery to check if the post being viewed has the class you're targeting, and if so, show the widget.
After adding the widget and hiding it with CSS the jQuery would look something like this:
<script> jQuery(document).ready(function() { if ( jQuery('article.post').hasClass('enter-category-class') ) { jQuery('enter-widget-id').show(); } }); </script>
If you add the widget and let me know what the category you want to target is I can give you a more accurate snippet.
Matt Whiteley – WhiteleyDesigns, GitHub
Designing, Developing & Creating with WordPressMarch 11, 2015 at 10:17 am #144027cookieandkate
MemberThank you for your suggestions! I don't love the idea of adding more scripts to my page and hiding the CSS on non-recipe posts. Surely there is another way to do it?
March 13, 2015 at 9:16 am #144296WhiteleyDesigns
MemberThe problem is you want to inject the widget between a bunch of other ones all in the same area, so there is no way to wrap the specific widget in something like has_term so it conditionally shows up based on whether the post has the term you are targeting.
You could register a new sidebar area and wrap it in a conditional to accomplish that, but that would be below all your widgets.
The other approach would be to create 2 new sidebars so you would have one that holds all the widgets above the conditional one (you could use the current one for that), the first new one would be specifically for the recipes widgets, which you could wrap in a conditional to display only on posts that have the term you're targeting, then the 2nd new widget you would move all the other widgets into so they show below it.
Then when you aren't on the recipe pages it would look exactly like it does now...but would technically be two separate sidebars stacked on top of each other, and when you are on the recipe post pages it would show as you'd like.
Matt Whiteley – WhiteleyDesigns, GitHub
Designing, Developing & Creating with WordPressMarch 13, 2015 at 4:45 pm #144333Badlywired
MemberI know that Genesis codes like to do everything with Genesis hooks, but could you not create a custom template for reciepes
along the lines of single-{post_type}.php i.e. single-reciepes.php
http://codex.wordpress.org/Template_Hierarchy
My techy blog WordPress and stuff badlywired.com
March 13, 2015 at 4:54 pm #144336WhiteleyDesigns
Membersingle-recipe.php would create a template for a post if she had a CPT (custom post type) called 'recipe'. She is trying to accomplish this based on if the post has a category of 'recipe'.
She would have to use category-recipe.php to do that...but she would have the same issue...she would still need to create multiple widget areas to enable the widget to be placed where she wants it since she wants it between widgets that are all in one sidebar.
Matt Whiteley – WhiteleyDesigns, GitHub
Designing, Developing & Creating with WordPressMarch 14, 2015 at 7:31 am #144384Badlywired
MemberAh ha I mis understood.
As an alternative,
what about using widget logic plugin with is_single() && is_categogry('recipes')
My techy blog WordPress and stuff badlywired.com
March 14, 2015 at 7:56 am #144389WhiteleyDesigns
MemberActually that seems like it would be the perfect solution. Great idea.
https://wordpress.org/plugins/widget-logic/
Matt Whiteley – WhiteleyDesigns, GitHub
Designing, Developing & Creating with WordPressMarch 16, 2015 at 5:27 pm #144677cookieandkate
MemberYou all are awesome. Thank you so much! I am going to check out your last idea. I found out that I could also built a custom recipe template through my recipe plugin and add that line at the end, which may be the easier solution. Thanks again!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.