Community Forums › Forums › Archived Forums › Design Tips and Tricks › Creating an in-content widget area?
Tagged: custom widget area, widget area, widgets
- This topic has 8 replies, 3 voices, and was last updated 9 years, 7 months ago by Skywalker.
-
AuthorPosts
-
September 5, 2014 at 5:13 pm #122999SkywalkerMember
I'd like to create a widget area that allows for the addition of content universally to all posts and pages.
So for instance you could add a text widget with contents that would be shown just before the content of each post or page:
"<div style="float:right;">Some script or ad code be displayed to the side of each article.</div>"Over here:
http://wpsites.net/web-design/add-widget-area-before-content/I found this code for adding a "before content" widget area:
genesis_register_sidebar( array( 'id' => 'before-content', 'name' => __( 'Before Content', 'magazine' ), 'description' => __( 'This goes before the content', 'magazine' ), ) ); add_action( 'genesis_before_content', 'wpsites_widget_before_content' ); function wpsites_widget_before_content() { if ( is_page() && is_active_sidebar('before-content') ) { genesis_widget_area( 'before-content', array( 'before' => '<div class="before-content" class="widget-area">', 'after' => '</div>', ) ); } }
However this seems to do exactly what it say - it adds it before the content. So if I create a Text Widget titled "Before-Content-Area" with the contents as above, the contents will float to the sidebar (if you have one), or just appear before the page/post content if the content is full width.
I read the Widgets API:
http://codex.wordpress.org/Widgets_APIBut I'm pretty new to this and I couldn't figure out how to add a simple in-content widget area. In this case I'd like the "Some script or ad code be displayed to the side of each article." to simply float to the side of each post/page. If there's a sidebar, I'd like it to not be above the sidebar, displaying only directly before the page/post contents.
Is there anyone that knows how to add that kind of widget area? Or perhaps direct me to some resources that could clear this up better for me?
http://www.omegacodex.com/September 5, 2014 at 5:39 pm #123002AnitaKeymasterTry Andrea's tutorial here - https://www.nutsandboltsmedia.com/how-to-add-a-widget-area-to-a-page-using-genesis/.
Love coffee, chocolate and my Bella!
September 5, 2014 at 7:11 pm #123006SkywalkerMemberThanks. I wanted to see if the hook locations genesis_before_post_title and genesis_after_post_title worked, so I added the following code to functions.php:
genesis_register_sidebar( array( 'id' => 'before-post-title', 'name' => __( 'Before Post Title', 'magazine' ), 'description' => __( 'This goes before post title', 'magazine' ), ) ); add_action( 'genesis_before_post_title', 'wpsites_widget_before_post_title' ); function wpsites_widget_before_post_title() { if ( is_page() && is_active_sidebar('before-post-title') ) { genesis_widget_area( 'before-post-title', array( 'before' => '<div class="before-post-title" class="widget-area">', 'after' => '</div>', ) ); } } genesis_register_sidebar( array( 'id' => 'after-post-title', 'name' => __( 'After Post Title', 'magazine' ), 'description' => __( 'This goes after post title', 'magazine' ), ) ); add_action( 'genesis_after_post_title', 'wpsites_widget_after_post_title' ); function wpsites_widget_after_post_title() { if ( is_page() && is_active_sidebar('after-post-title') ) { genesis_widget_area( 'after-post-title', array( 'before' => '<div class="after-post-title" class="widget-area">', 'after' => '</div>', ) ); } }
But while the widget locations show up under Appearance>Widgets, and I have added Text widgets to those widget locations, there doesn't seem to be any effect. The text I added is not present.
Is there a bug in my code?
September 6, 2014 at 2:42 am #123021Brad DaltonParticipantNo bug.
The old loop hooks don't work in the new HTML 5 themes.
Use genesis_entry_header to add a widget after post titles in replace of both genesis_after_post_title and genesis_before_post_title.
Use a 3rd parameter for positioning priority.
Note: genesis_before_content is NOT a loop hook so works in any theme.
September 6, 2014 at 9:20 am #123042SkywalkerMemberThanks for the info 🙂
So - with genesis_entry_header, how does one replicate the genesis_after_post_title and genesis_before_post_content hooks?
By default it seems to do genesis_before_post_title. I tried added parameters 1, 2, and 3, but all were in the before post title location.
September 6, 2014 at 9:46 am #123046Brad DaltonParticipantSeptember 6, 2014 at 10:20 am #123050SkywalkerMemberThanks so much 🙂 Any priority of 10 or higher seems to accomplish what I want - the content shows after the post title.
I read that priority tutorial though and I'm still confused however - how would we know what priority is needed for genesis_entry_header to place it before or after the post title, without trial and error?
As some of the new hooks take the place of multiple old loop hooks, what parameters do we need to input to match the locations of the old hooks? Is there a reference that lists this?
September 6, 2014 at 10:32 am #123054Brad DaltonParticipanthttp://wpsites.net/wordpress-themes/new-genesis-2-0-loop-hooks-how-to-use-them/
Please mark this as resolved.
September 6, 2014 at 10:48 am #123056SkywalkerMemberThanks again.
-
AuthorPosts
- The topic ‘Creating an in-content widget area?’ is closed to new replies.