【发布时间】:2018-04-25 10:50:45
【问题描述】:
我已经制作了一个模板并为推荐页面分配了一个模板。 以下所有代码都放在我的模板文件中。
我的问题是 Next 和 Prev 链接甚至没有显示在推荐页面上。我只想使用get_posts 查询来检索数据。
如何显示get_posts 的分页?
global $post;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 0;
$postsPerPage = 2;
$postOffset = $paged * $postsPerPage;
$args_testimonial = array(
'post_type' => 'testimonial',
'offset' => $postOffset,
'posts_per_page' => $postsPerPage,
'orderby'=> 'title',
'order'=>'DESC'
);
$data_testimonial = get_posts( $args_testimonial );
foreach ( $data_testimonial as $post_testimonial ) : setup_postdata( $post_testimonial );
$testimonee_title = get_the_title($post_testimonial->ID);
$testimonee_post = get_post($post_testimonial->ID);
$testimonee_content = $testimonee_post->post_content;
$testimonee_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_testimonial->ID ), 'single-post-thumbnail' );
if ( $testimonee_title || $testimonee_content || $testimonee_image ) { ?>
<div class="single-testimonial">
<?php if ( $testimonee_content ) { ?>
<div class="testimonial-content">
<p>Dear Gary’s Carpet Cleaning</p>
<p><?php echo $testimonee_content; ?></p>
</div>
<?php }
if ( $testimonee_title || $testimonee_image ) { ?>
<div class="testimonial-person">
<div class="testimonial-image">
<?php if ( $testimonee_image ) { ?>
<img src="<?php echo $testimonee_image[0]; ?>" alt=" "/>
<?php } else { ?>
<img src="<?php echo get_template_directory_uri(); ?>/assets/images/testimonial-dummy-image.png" alt=" "/>
<?php } ?>
</div>
<?php if( $testimonee_title ) { ?>
<div class="testimonial-name">
<p><strong>-<?php echo $testimonee_title; ?></strong></p>
</div>
<?php } ?>
</div>
<?php } ?>
</div>
<?php } endforeach;
next_posts_link( 'Prev');
previous_posts_link('Next');
wp_reset_postdata();
【问题讨论】:
-
你找到解决办法了吗?
-
@rowmoin 还没有,我已经发布了这个问题以寻求解决方案
-
我试图在下面的答案部分给出一个解决方案。
标签: php wordpress function pagination