【发布时间】:2018-07-02 08:19:12
【问题描述】:
我应该怎么做才能在我的 author.php 页面中只显示某个作者的帖子?我不是指特定的作者(使用作者 ID),而是作者的默认页面。使用当前代码,它显示来自所有其他作者的帖子。我应该使用特定查询吗?
<?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$custom_args = array(
'post_type' => 'post',
// 'order' => 'DESC',
'posts_per_page' => 10,
'paged' => $paged
);
// custom query
$recent_posts = new WP_Query($custom_args);
// check that we have results
if($recent_posts->have_posts()) : ?>
<ul class="article_list">
<?php
// start loop
while ($recent_posts->have_posts() ) : $recent_posts->the_post(); ?>
<li class="regular">
<a href="<?php echo get_permalink(); ?>">
<div class="text">
<p class="category"><?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?></p>
<p class="autor"><?php the_author(); ?></p>
<h3 class="article_title"><?php echo mb_strimwidth(get_the_title(), 0, 80, '...'); ?></h3>
<p class="date"><?php echo get_the_date( 'Y-m-d' ); ?></p>
</div>
<div class="mask">
<?php
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
echo '<div class="art_img" style="background: url('. $url.')"></div>';
?>
</div>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif;
echo '<div class="pagination">';
if(function_exists('wp_pagenavi')) { wp_pagenavi(array( 'query' => $recent_posts )); }
echo '</div>';
wp_reset_postdata();
?>
【问题讨论】: