Community Forums › Forums › Archived Forums › General Discussion › Load author info after header
Tagged: author box, child theme, hooks
- This topic has 5 replies, 2 voices, and was last updated 9 years, 5 months ago by upthink.
-
AuthorPosts
-
April 17, 2015 at 12:19 pm #148265readytoblogdesignsMember
Hi! I'm having a problem that might be incredibly easy to solve but I'm just not seeing it. I'm using the following code to output an author box on posts in a certain category:
/** Display author box on single posts */
add_filter( 'get_the_author_genesis_author_box_single', '__return_true' );//* Remove the author box on single posts XHTML Themes
remove_action( 'genesis_after_post', 'genesis_do_author_box_single' );//* Remove the author box on single posts HTML5 Themes
remove_action( 'genesis_after_entry', 'genesis_do_author_box_single', 8 );add_action('genesis_before_entry', 'vt_author_box', 5);
function vt_author_box() {
$output = '';if( get_the_author_meta('genesis_author_box_single') == 1 ) :
$output .= '<div class="author-box">';
$output .= '<h3 class="author-title">Staff Blog</h3>';
$output .= get_avatar(get_the_author_meta('user_email'), 75);
$output .= get_the_author();
$output .= '<div class="author-inner">';
$output .= '<div class="inner-left">';$output .= '</div>';
$output .= '<div class="inner-right">';$output .= wpautop(get_the_author_meta('description'));
$output .= '</div>';
$output .= '<div class="clear"></div>';
$output .= '</div>';
$output .= '</div>';
endif;if ( is_single() && in_category( '49' ) ) {
echo $output;
}
}The problem for me lies here: add_action('genesis_before_entry', 'vt_author_box', 5);
I actually need this to show after the header (full width, outside the wrap), but when I hook it in any higher than before entry, the data gets stripped out of the author box. Ideally, I'd like to use: add_action('genesis_after_header', 'vt_author_box', 5);
Am I being dumb? Is there a way to call the author name/description right after the header on a post page?
http://67.20.119.100/the-truth-about-poverty-6/April 18, 2015 at 8:39 am #148349upthinkParticipantWhy not do something like this:
add_action( 'genesis_header', 'vt_author_box', 99 );
April 18, 2015 at 8:53 am #148350readytoblogdesignsMemberHmmm, tried that and it just puts it above the header with the data still stripped out. I'll move it to where I actually want it, the box itself is fine, it's just that the actual author name and description won't get pulled through if I hook it in anywhere above genesis_before_entry...Thanks for having a look, I really appreciate it! Not sure if it's possible to do what I'm trying to do, but I don't really see why not...
April 18, 2015 at 8:59 pm #148391upthinkParticipantOk I see what you mean. basically the function get_the_author() will only work in the WP loop. So whenever you go outside the loop it becomes unavailable. I guess something like this can work:
function vt_author_box() { global $post; $author_id=$post->post_author; $output = ”; if( get_the_author_meta(‘genesis_author_box_single’, $author_id) == 1 ) : $output .= ‘<div class=”author-box”>'; $output .= ‘<h3 class=”author-title”>Staff Blog</h3>'; $output .= get_avatar(get_the_author_meta(‘user_email’, $author_id), 75); $output .= get_the_author_meta(‘display_name’, $author_id); $output .= ‘<div class=”author-inner”>'; $output .= ‘<div class=”inner-left”>'; $output .= ‘</div>'; $output .= ‘<div class=”inner-right”>'; $output .= wpautop(get_the_author_meta(‘description’, $author_id)); $output .= ‘</div>'; $output .= ‘<div class=”clear”></div>'; $output .= ‘</div>'; $output .= ‘</div>'; endif; if ( is_single() && in_category( ’49’ ) ) { echo $output; } }
Not tested - you may need to tweak it or it may give an error
April 19, 2015 at 6:45 am #148410readytoblogdesignsMemberI did just a bit of tweaking and this did the trick! If anyone is after something similar, here's what gave me the result I was after!
function vt_author_box() {
global $post;
$author_id=$post->post_author;
$output = '';if( get_the_author_meta('genesis_author_box_single', $author_id) == 1 ) :
$output .= '<div class="author-box">';
$output .= '<h3 class="author-title">Staff Blog</h3>';
$output .= get_avatar(get_the_author_meta('user_email'), 75);
$output .= get_the_author();
$output .= '<div class="author-inner">';
$output .= '<div class="inner-left">';$output .= '</div>';
$output .= '<div class="inner-right">';
$output .= wpautop(get_the_author_meta('display_name', $author_id));
$output .= wpautop(get_the_author_meta('description', $author_id));$output .= '</div>';
$output .= '<div class="clear"></div>';
$output .= '</div>';
$output .= '</div>';
endif;if ( is_single() && in_category( '49' ) ) {
echo $output;
}
}Thanks a million, upthink! Let me know where I can send your virtual gift basket! 🙂
April 19, 2015 at 11:34 pm #148491upthinkParticipantGlad to help 🙂
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.