Community Forums › Forums › Archived Forums › Design Tips and Tricks › After single post widget
Tagged: after content, Sidebar, widget
- This topic has 4 replies, 3 voices, and was last updated 11 years, 3 months ago by Scott Buehler.
-
AuthorPosts
-
September 22, 2013 at 5:46 pm #63781brankicaMember
I was following this tutorial http://my.studiopress.com/tutorials/add-genesis-box/ so I can add a box on single posts after content.
The code isn't working for some reason.
I have a widget I added that displays on single posts as a featured box under header and I notice a few differences but considering I don't know PHP I am not sure what I am missing.
So the code that worked for my featured box below header is
genesis_register_sidebar( array( 'id' => 'featured-box', 'name' => __( 'Featured Box', 'fcc' ), 'description' => __( 'This is the featured box.', 'fcc' ), ) ); add_action( 'genesis_after_header', 'genesis_featured_box' ); function genesis_featured_box() { if ( is_single() && is_active_sidebar( 'featured-box' ) ) { echo '<div class="featured-box">'; dynamic_sidebar( 'featured-box' ); echo '</div><!-- end .featured-box -->'; } }
The tutorial is showing
//* Register Genesis box widget area genesis_register_sidebar( array( 'id' => 'genesis-box', 'name' => __( 'Genesis Box', 'themename' ), 'description' => __( 'This is a widget area that can be placed after the post', 'themename' ), ) ); //* Hook Genesis box widget area after post content add_action( 'genesis_after_post_content', 'sp_genesis_box', 9 ); function sp_genesis_box() { if ( is_singular( 'post' ) ) genesis_widget_area( 'after-post', array( 'before' => '<div class="genesis-box widget-area">', 'after' => '</div>', ) ); }
The things I see are different are for example in first code there is "IS SINGLE" while in the second "IS SINGULAR". I definitely don't know enough about PHP to figure this one out so if any one can help me figure out how to add a content box after main post content (above author box) I would really appreciate it.
I do have the hooks plugin if that helps but I don't know how to use this after post box and limit it to single post only.
Thanks
September 22, 2013 at 6:32 pm #63797Brad DaltonParticipantThe code uses the old hooks which is why it ay not work if your child theme is running HTML 5.
Try this:
//* Register Genesis box widget area genesis_register_sidebar( array( 'id' => 'genesis-box', 'name' => __( 'Genesis Box', 'themename' ), 'description' => __( 'This is a widget area that can be placed after the post', 'themename' ), ) ); //* Hook Genesis box widget area after post content add_action( 'genesis_entry_footer', 'sp_genesis_box', 9 ); function sp_genesis_box() { if ( is_single( ) ) genesis_widget_area( 'after-post', array( 'before' => '<div class="genesis-box widget-area">', 'after' => '</div>', ) ); }
Will only work on HTML 5 themes.
Change the 9 if needed for positioning priority http://wpsites.net/web-design/3rd-parameter-action-hooks/
If you're running XHTML, change:
genesis_entry_footer
To this:
genesis_after_post_content
October 13, 2013 at 7:44 am #66500Scott BuehlerMemberThis doesn't work for me either. On new Lifestyle theme:
genesis_register_sidebar( array( 'id' => 'genesis-box', 'name' => __( 'Genesis Box', 'lifestyle' ), 'description' => __( 'This is a widget area that can be placed after the post', 'lifestyle' ), ) );
//* Hook Genesis box widget area after post content add_action( 'genesis_entry_footer', 'sp_genesis_box', 9 ); function sp_genesis_box() { if ( is_single( ) ) genesis_widget_area( 'after-post', array( 'before' => '<div class="genesis-box widget-area">', 'after' => '</div>', ) ); }
Regular post page doesn't display the genesis box. Using HTML5
TygrScott on Social Media
October 13, 2013 at 9:12 am #66504Brad DaltonParticipantSorry, typo, my bad:
Tested and works
Please copy 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++
October 13, 2013 at 6:30 pm #66557Scott BuehlerMemberYep, the error was the line
genesis_widget_area( 'after-post', array(
Needed to be
genesis_widget_area( 'genesis-box', array(
Thanks Brad. Genesis support showed me the error and I appreciate both you and StudioPress support very much!
TygrScott on Social Media
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.