我正在制作一个自定义的创世主题,并有一个自定义的作者。php文件,该文件拉入各种自定义字段(使用高级自定义字段),并将作者配置文件页面中的作者元信息添加到页面中。。。它还显示他们的最新帖子。
如果作者已经为其分配了帖子,那么这一点非常有效。如果没有,页面将不会输出通常从作者档案中提取的任何内容。。。
我搜索了StackExchange,虽然这已经被提到过几次,但我似乎找不到一个有效的答案。
我需要作者。php页面输出作者信息,无论用户是否有帖子。如果没有,配置文件元和自定义字段仍应显示,最近的帖子部分不应显示其中的任何帖子。
这是我的作者。php代码。
// 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"><h2>Cuisines</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"><h2>Based In</h2>\';
the_field(\'based_in\', $display_id);
echo \'</div>\';
// Status
echo \'<div class="widget-sidebar-section status"><h2>Status</h2>\';
the_field(\'status\', $display_id);
echo \'</div>\';
// Signature Dish
echo \'<div class="widget-sidebar-section sig-dish"><h2>Signature Dish</h2>\';
the_field(\'signature_dish\', $display_id);
echo \'</div>\';
// Amazon Store Button
?>
<a href="<?php the_field(\'amazon_store_link\', $display_id);?>"><button>See 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();