author.php not showing content if Author has no Posts
I am making a custom Genesis theme, and have a custom author.php file that pulls in various custom fields (Using Advanced Custom Fields), and author meta information to the page from the author profile page... It also displays their latest posts.
This works perfectly, IF the author has posts assigned to them. If they don't, the page doesn't output any of the content that is normally pulled from the authors profile...
I've searched StackExchange, and whilst this has been mentioned a few times, I can't seem to find an answer that works.
I need the author.php page to output the author information whether the user has posts or not. If they don't, the profile meta and custom fields should still display, and the recent posts section should not show any posts in it.
Here's my author.php code.
// remove Genesis default loop
remove_action( 'genesis_loop', 'genesis_do_loop' );
// Remove Header Markup
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
remove_action( 'genesis_before_loop', 'genesis_do_author_title_description', 15 );
//remove the default sidebar widget setup
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
remove_action( 'genesis_sidebar_alt', 'genesis_do_sidebar_alt' );
// Add in the layout sections
add_action('genesis_loop','add_top_author_section');
add_action('genesis_sidebar','add_sidebar_info');
add_action('genesis_after_content_sidebar_wrap', 'add_latest_posts');
function add_top_author_section() {
//vars
$avatar = get_avatar( get_the_author_meta( 'ID' ), apply_filters( 'th_author_bio_avatar_size', 300 ) );
$display_name = get_the_author_meta( 'display_name' );
?
div class="author-details"
div class="left-profile"
?php echo $avatar; ?
/div
div class="right-profile"
h2?php echo $display_name; ?/h2
p?php the_author_meta('description'); ?
/div
/div
?php
}
function add_sidebar_info() {
// Cuisines
$user_id = get_the_author_meta( 'ID' );
$display_id = 'user_'.$user_id;
$terms = get_field('types_of_cuisine2', $display_id);
if ( $terms ) {
echo 'div class="widget-sidebar-section cuisines"h2Cuisines/h2';
foreach ( $terms as $term ) :?
a href="http://tastehaus.flywheelsites.com/recipes/?_sfm_cuisine=?php echo $term; ?"?php echo $term; ?/a
?php endforeach;
echo '/div';
}
// Based In
echo 'div class="widget-sidebar-section based-in"h2Based In/h2';
the_field('based_in', $display_id);
echo '/div';
// Status
echo 'div class="widget-sidebar-section status"h2Status/h2';
the_field('status', $display_id);
echo '/div';
// Signature Dish
echo 'div class="widget-sidebar-section sig-dish"h2Signature Dish/h2';
the_field('signature_dish', $display_id);
echo '/div';
// Amazon Store Button
?
a href="?php the_field('amazon_store_link', $display_id);?"buttonSee My Recommended Tools/button /a
?
}
function add_latest_posts() {
echo 'div class="user-latest-posts"';
echo 'h2 style="text-align:center;"Recent Posts by '. get_the_author_meta( 'first_name' ) .'/h2';
echo '/div';
global $post;
// arguments, adjust as needed
$args2 = array(
'author' = get_the_author_meta( 'ID' ),
'post_type' = array( 'recipes', 'tools', ),
'orderby' = 'post_date',
'order' = 'ASC',
'posts_per_page' = 6,
);
/*
Overwrite $wp_query with our new query.
The only reason we're doing this is so the pagination functions work,
since they use $wp_query.
*/
global $wp_query;
$wp_query = new WP_Query( $args2 );
if ( have_posts() ) :
echo 'div class="posts-query"';
while ( have_posts() ) : the_post(); ?
div class="query-post"
div class="query-padding"
div clss="posts-image"
?php the_post_thumbnail("thumbnail");?
/div
div class="post-categories"
?php $postType = get_post_type_object(get_post_type());
if ($postType) {
echo esc_html($postType-labels-singular_name);
}
?
/div
div class="posts-title"
a href="?php the_permalink(); ?"
h3
?php the_title() ?
/h3
/a
/div
/div
/div
? endwhile;
echo '/div';
do_action( 'genesis_after_endwhile' );
endif;
wp_reset_query();
}
genesis();
Topic user-meta author genesis-theme-framework custom-field Wordpress
Category Web