【发布时间】:2017-03-12 10:29:14
【问题描述】:
我在为自定义 wordpress 查询添加分页时遇到困难,该查询显示来自类别“博客”的最新作者帖子。我在stackoverflow的某个地方找到了这段代码。有人可以帮我/提供一些提示如何为此查询添加分页吗?我已经花费了几个小时,但无法想出可行的方法。
最适合我的是数字分页: 1 | 2 | 3 | 4 |等等……
functions.php
function the_latest_author_posts($post) {
$relatedargs = array(
'author' => $post->post_author,
'post__not_in' => array( $post->ID),
'posts_per_page' => 8,
'category_name' => 'blog',
);
$relatedquery = new WP_Query( $relatedargs );
while($relatedquery->have_posts()){
$relatedquery->the_post();
$ID = get_the_ID();
?>
<div class="post-blog">
<?php
if(has_post_thumbnail()) {
$relatedthumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($ID), 'medium', false);
$relatedthumbnail_large = wp_get_attachment_image_src( get_post_thumbnail_id($ID), 'full', false);
?>
<?php } ?>
<h1><a href="<?php the_permalink(); ?>"><span><?php the_title(); ?></span></a></h1>
<h6><i class="fa fa-clock-o" aria-hidden="true"></i> <?php echo get_the_time('j') . '/' . get_the_time('m') . '/' . get_the_time('Y') . ' '; ?></h6>
<?php
$content = get_the_content();
echo wp_trim_words( $content , '25' ); ?>
</div>
<?php wp_reset_postdata();}}
我在我的模板中这样调用这个函数:
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
the_latest_author_posts($post);
}
}
?>
【问题讨论】:
标签: php wordpress pagination author