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.
Community Forums › Forums › Archived Forums › General Discussion › Below content widget appears above content
Tagged: CPT, genesis_after_post_content, widget
- This topic has 13 replies, 3 voices, and was last updated 10 years, 10 months ago by songdogtech.
-
AuthorPosts
-
December 18, 2013 at 8:26 pm #80083songdogtechParticipant
I'm trying to add a below content widget to a Custom Post Type template. but the widget appears above the content. Nothing I do makes this change.
I'm using a CPT and also showing custom field data with a wp_query.
This is my page template called single-hhdata.php
function hhdata_loop() { global $post; $args = array( 'post_type' => 'hh-data', 'posts_per_page' => 1, 'post_status' => 'publish', ); $wp_query = new WP_Query( $args ); if ( have_posts() ) : while ( have_posts() ) : the_post(); //echoing a lot of custom field data endwhile; endif; wp_reset_query(); } add_action( 'genesis_loop', 'hhdata_loop' ); genesis();
This is what I'm using in functions.php, and it inits the widget in admin and shows the widget content on a single CPT page, but the contents of the widget appear above the content, not below:
/** Register Below HH Post Widget area */ genesis_register_sidebar( array( 'id' => 'below-hh-area', 'name' => __( 'Below HH Area Widget', '$text_domain' ), 'description' => __( 'This is the Below HH Area section', '$text_domain' ), ) ); add_action( 'genesis_after_post_content', 'below_hh_area_widget' ); function below_hh-area_widget() { if ( is_singular( 'hh-data' ) && is_active_sidebar('below-hh-area') ) { genesis_widget_area( 'below-hh-area', array( 'before' => '<div class="below-hh-area widget-area">', 'after' => '</div>', ) ); } }
I use this for a widget after posts, but removing this doesn't make the after CPT widget placement, and this widget doesn't show on the CPT template above.
add_action( 'genesis_after_post_content', 'focus_after_post' ); function focus_after_post() { if ( ! is_singular( 'post' ) ) return; genesis_widget_area( 'after-post', array( 'before' => '<div class="after-post widget-area">', ) ); }
Is the issue the CPT or the wp_query loop showing the custom field data? Or is there a conflict between the two after post calls?
December 18, 2013 at 11:19 pm #80104Brad DaltonParticipantFirstly, you need to use the conditional tag for a custom post type.
This is wrong
if ( is_singular( 'hh-data' )
This works
if( 'hh-data' == get_post_type()
Try adding the 3rd parameter for positioning
Example
add_action( 'genesis_after_post_content', 'below_hh_area_widget', 11 );
Secondly, are you running XHTML or HTML 5?
Link to your site please.
December 19, 2013 at 10:27 am #80212songdogtechParticipantThanks, I did have the conditional wrong, and I didn't know there was a parameter for positioning, but no luck with either of those changes.
This is Focus XHTML, but once I get everything done, I'm converting it to Focus Pro HTML5 re: http://wpsites.net/wordpress-themes/how-to-convert-your-studiopress-child-theme-from-xhtml-to-html-5/
And this is on my dev server, so it's not accessible.
The full focus_after_post function is below, which I forgot to include earlier; is there a conflict here?
add_action( 'genesis_after_post_content', 'focus_after_post' ); function focus_after_post() { if ( ! is_singular( 'post' ) ) return; genesis_widget_area( 'after-post', array( 'before' => '<div class="after-post widget-area">', ) ); } genesis_register_sidebar( array( 'id' => 'after-post', 'name' => __( 'After Single Post Widget', '$text_domain' ), 'description' => __( 'This is the After Post Widget section.', '$text_domain' ), ) );
And this is the source, which shows the widget is dumping the text below
entry-content
:<div id="inner"> <div class="wrap"> <div id="content-sidebar-wrap"> <div id="content" class="hfeed"> <div class="post-9999 type-hh-data hentry entry"> <div class="entry-content"></div> <div class="below-hhdata widget-area"> <div id="text-12" class="widget widget_text"> <div class="widget-wrap"><div class="textwidget"> Below HHdata text in widget </div> </div> </div>
December 20, 2013 at 1:43 am #80413Brad DaltonParticipantThe code for the widget is wrong.
Change this:
genesis_widget_area( 'after-post', array( 'before' => '<div class="after-post widget-area">', ) ); }
To this:
genesis_widget_area( 'after-post', array( 'before' => '<div class="after-post widget-area">', 'after' => '</div>', ) ); }
I would also include the 3rd parameter as you're using the same hook twice;
add_action( 'genesis_after_post_content', 'focus_after_post', 15 );
December 20, 2013 at 10:33 am #80465songdogtechParticipantThanks, but still no luck with this:
/** Register After Single Post Widget Area */ genesis_register_sidebar( array( 'id' => 'after-post', 'name' => __( 'After Single Post Widget', '$text_domain' ), 'description' => __( 'This is the After Post Widget section.', '$text_domain' ), ) ); add_action( 'genesis_after_post_content', 'focus_after_post', 15 ); function focus_after_post() { if ( ! is_singular( 'post' ) ) return; genesis_widget_area( 'after-post', array( 'before' => '<div class="after-post widget-area">', 'after' => '</div>', ) ); } /** Register Below HHData Post Widget Area */ genesis_register_sidebar( array( 'id' => 'below-hhdata', 'name' => __( 'Below HHdata Widget', '$text_domain' ), 'description' => __( 'This is the Below HHdata section', '$text_domain' ), ) ); add_action( 'genesis_after_post_content', 'below_hhdata_widget', 11 ); function below_hhdata_widget() { if( 'horoscope' == get_post_type() ) { genesis_widget_area( 'below-hhdata', array( 'before' => '<div class="below-hhdata widget-area">', 'after' => '</div>', ) ); } }
Page template called single-hhdata.php
function hhdata_loop() { global $post; $args = array( 'post_type' => 'hh-data', 'posts_per_page' => 1, 'post_status' => 'publish', ); $wp_query = new WP_Query( $args ); if ( have_posts() ) : while ( have_posts() ) : the_post(); //echoing a lot of custom field data endwhile; endif; wp_reset_query(); } add_action( 'genesis_loop', 'hhdata_loop' ); genesis();
December 20, 2013 at 12:50 pm #80485Genesis DeveloperMemberare you using HTML5 markup? in your functions.php file have this code 'add_theme_support( 'html5' );' ?
December 20, 2013 at 3:44 pm #80505songdogtechParticipantThis is Focus XHTML.
December 20, 2013 at 11:01 pm #80566Genesis DeveloperMemberThen this can be work
add_action( 'genesis_after_post_content', ''below_hhdata_widget'' ); function below_hhdata_widget(){ if(( 'hh-data' == get_post_type() ) && is_single() ) { genesis_widget_area( 'below-hhdata', array( 'before' => '<div class="below-hhdata widget-area">', 'after' => '</div>', ) ); } }
December 21, 2013 at 1:51 am #80571Brad DaltonParticipantI have tested this code and it works perfectly:
Change portfolio to the name of your CPT.
This code works on HTML 5 themes only.
I suggest you convert to HTML 5. http://cobaltapps.com/genesis-xhtml-to-html5-css-converter/
I didn't test the code on a XHTML theme because of the time involved to setup a CPT on a XHTML site.
For sites running XHTML, change
genesis_entry_footer
to
genesis_after_post_content
December 21, 2013 at 2:47 am #80575Genesis DeveloperMemberYes. if he use the HTML5 markup then your code will work on his child theme. But he is using the XHTML and XHTML is not supporting the 'genesis_enrty_footer' hook. It is for HTML5 only.
December 21, 2013 at 4:34 am #80583Brad DaltonParticipant@gemrock Your code is wrong. http://www.studiopress.community/topic/below-content-widget-appears-above-content/#post-80566
I clearly stated that the code works for HTML 5
Its a 2 minute job to update to HTML 5.
December 27, 2013 at 9:43 am #81405songdogtechParticipant@braddalton, thanks, but I'm still beating my head against the keyboard with this. I converted to HTML5.
All the other post and page before_entry and entry_footer widgets work, and deleting them doesn't help with this one.
I added a before_entry hhdata widget, but both of these render above the content. Tried changing the 3rd parameter in many different ways and with the other widgets with no luck.
/** Register Above hhdata Widget Area */ genesis_register_sidebar( array( 'id' => 'above-hhdata', 'name' => __( 'Above hhdata Widget', '$text_domain' ), 'description' => __( 'This is the Above hhdata section', '$text_domain' ), ) ); add_action( 'genesis_before_entry', 'above_hhdata_widget'); function above_hhdata_widget() { if( 'hhdata' == get_post_type() && is_single() ) { genesis_widget_area( 'above-hhdata', array( 'before' => '<div class="above-hhdata widget-area">', 'after' => '</div>', ) ); } } /** Register Below hhdata Widget Area */ genesis_register_sidebar( array( 'id' => 'below-hhdata', 'name' => __( 'Below hhdata Widget', '$text_domain' ), 'description' => __( 'This is the Below hhdata section', '$text_domain' ), ) ); add_action( 'genesis_entry_footer', 'below_hhdata_widget', 11 ); function below_hhdata_widget() { if( 'hhdata' == get_post_type() && is_single() ) { genesis_widget_area( 'below-hhdata', array( 'before' => '<div class="below-hhdata widget-area">', 'after' => '</div>', ) ); } }
The page template:
function hhdata_loop() { global $post; $args = array( 'post_type' => 'hhdata', 'posts_per_page' => 1, 'post_status' => 'publish', ); $wp_query = new WP_Query( $args ); if ( have_posts() ) : while ( have_posts() ) : the_post(); //echoing custom field data endwhile; endif; wp_reset_query(); } add_action( 'genesis_loop', 'hhdata_loop' ); genesis();
December 27, 2013 at 1:04 pm #81434Brad DaltonParticipantDecember 27, 2013 at 1:54 pm #81443songdogtechParticipantThanks for your help; this is still on a demo server, but I emailed the demo site login and password.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.