Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add content before all posts in a category
Tagged: add text box, custom content
- This topic has 10 replies, 3 voices, and was last updated 10 years, 10 months ago by
Brad Dalton.
-
AuthorPosts
-
May 21, 2014 at 2:28 pm #106215
mercurialist
MemberI'd like to add some custom text before the content of all posts in a specific category. I would like for this text to appear below the headline and before the post content begins.
I have a feeling the process will be similar to what is explained here, only I'm not creating a box below the content.
I'm using the Apparition theme. URL is not included because site is being developed offline.
May 21, 2014 at 3:01 pm #106219Lauren @ OnceCoupled
MemberYep, you want to use the same general concept, only you want to hook your widget area into a different location. This line
add_action( 'genesis_after_post_content', 'sp_genesis_box', 9 );
should be changed to accomplish that. You can find a nice guide to the various hooks here: http://genesistutorials.com/visual-hook-guide/. You'll also need some conditional logic to check that the category ID is the one you want: http://codex.wordpress.org/Conditional_Tags#A_Category_Page.Best,
Lauren
We create mobile-first, PageSpeed-optimized, pixel-perfect custom themes! https://www.oncecoupled.com
May 21, 2014 at 7:17 pm #106243mercurialist
MemberThanks for your help, Lauren. Unfortunately, it's still not working, although I may have missed something when implementing this. Here's the code that I placed in functions.php:
//* Register before post widget area genesis_register_sidebar( array( 'id' => 'before-post', 'name' => __( 'Before Post', 'apparition' ), 'description' => __( 'This is a widget area that can be placed after the post', 'apparition' ), ) ); //* Hook before post widget area before post content add_action( 'genesis_entry_content', 'sp_before_post_widget' ); function sp_before_post_widget() { if ( is_single() && in_category( 'old-blog' )) genesis_widget_area( 'before-post', array( 'before' => '<div class="before-post widget-area">', 'after' => '</div>', ) ); }
The widget is registered, but when I add a text widget, enter some text, and save it, nothing changes.
May 21, 2014 at 8:58 pm #106249Lauren @ OnceCoupled
MemberSounds like a problem with your conditional. If you try removing the conditional, does the widget area show up?
We create mobile-first, PageSpeed-optimized, pixel-perfect custom themes! https://www.oncecoupled.com
May 22, 2014 at 4:26 am #106289Brad Dalton
ParticipantPlease copy ALL the code from the view raw link and paste it at the end of your child themes functions.php file using a text editor like Notepad++
May 22, 2014 at 6:22 am #106293mercurialist
MemberLauren: I removed the conditional and it's the same problem. I see the widget area in "Appearance>>Widgets," but I nothing changes on the page when I actually place a widget there.
Brad: Thanks for the code. I added it to my functions.php file, only changing the category slug. Same problem, though. Widget area appears in "Appearance>>Widgets," but nothing appears on the site when I actually add a widget.
May 22, 2014 at 8:06 am #106323Brad Dalton
ParticipantI tested the code today and it works perfectly.
Did you save the widget after populating it in the new area?
What widget did you use?
May 22, 2014 at 10:06 am #106343mercurialist
MemberYes, I saved the widget after populating it. I have experimented with a text widget, category widget, and the "meta" widget that displays meta content. Still nothing.
It makes no sense to me why your code wouldn't work for me. Really weird.
May 22, 2014 at 10:26 am #106348mercurialist
MemberThis reply has been marked as private.May 23, 2014 at 5:15 pm #106554mercurialist
MemberUpdate: I tried Brad's code using a different child theme (Parallax Pro). The code works just fine with this theme, and it's the theme I'll be using for my project. Thanks again, Brad!
There must be an issue with the Apparition theme that prevents the hook from working.
May 23, 2014 at 10:58 pm #106570Brad Dalton
ParticipantYou're welcome.
Will post back if i get the chance to work out why it didn't work in Apparition. Maybe there's another function using the same hook already.
-
AuthorPosts
- The topic ‘Add content before all posts in a category’ is closed to new replies.