• 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

How to build custom widget area for recipes above related posts

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 › How to build custom widget area for recipes above related posts

This topic is: not resolved

Tagged: After Entry, New Widget Area, related posts, text widget

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

    Hi 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,
    Kate

    http://cookieandkate.com
    March 10, 2015 at 2:43 pm #143947
    WhiteleyDesigns
    Member

    My 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 WordPress

    March 11, 2015 at 10:17 am #144027
    cookieandkate
    Member

    Thank 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 #144296
    WhiteleyDesigns
    Member

    The 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 WordPress

    March 13, 2015 at 4:45 pm #144333
    Badlywired
    Member

    I 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 #144336
    WhiteleyDesigns
    Member

    single-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 WordPress

    March 14, 2015 at 7:31 am #144384
    Badlywired
    Member

    Ah 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 #144389
    WhiteleyDesigns
    Member

    Actually 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 WordPress

    March 16, 2015 at 5:27 pm #144677
    cookieandkate
    Member

    You 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!

  • 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

© 2023 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