如何将分页添加到自定义Word Press循环中



这是我的代码-

<div class="gallery-posts">
<?php
$args = array( 
'post_type' => 'post', 
'order' => 'ASC',
'numberposts' => 4
);
$product_posts = get_posts( $args ); 
?>
<?php foreach ( $product_posts as $post ) : setup_postdata( $post ); ?>    
<?php $videos = rwmb_meta( '_video-link' );
foreach ( $videos as $video ); ?>   
<div 
class="card-container video-link" 
data-link="<?php echo $video['src']; ?>" 
title="<?php the_title(); ?>"
description="<?php echo ( get_post_meta( get_the_ID(), '_description', true ) ); ?>"
thumbnail-link="<?php the_post_thumbnail_url()  ?>">
<figure class="gallery-image">
<?php the_post_thumbnail(); ?>
<div class="gallery-image-text">
<p><?php the_title() ?></p>
<i class="fas fa-play"></i>
</div>
</figure>
</div>
<?php endforeach; wp_reset_postdata(); ?>
</div>

我想设置它,以便每当有4个以上的帖子时,下一个/上一个都会显示。

使用常规的Word Press循环,我知道你可以只做_posts_pagination,但这在这里不起作用。

需要添加哪些内容才能使用此循环进行分页?

这样更改代码:

<div class="gallery-posts">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 
'post_type' => 'post', 
'order' => 'ASC',
'posts_per_page' => 4,
'paged' => $paged
);
$product_posts = get_posts( $args ); 
foreach ( $product_posts as $post ) : setup_postdata( $post ); 
$videos = rwmb_meta( '_video-link' );
foreach ( $videos as $video ):
?>
<div class="card-container video-link" data-link="<?php echo $video['src']; ?>" title="<?php the_title(); ?>"  description="<?php echo ( get_post_meta( get_the_ID(), '_description', true ) ); ?>" thumbnail-link="<?php the_post_thumbnail_url()  ?>">
<figure class="gallery-image">
<?php the_post_thumbnail(); ?>
<div class="gallery-image-text">
<p><?php the_title() ?></p>
<i class="fas fa-play"></i>
</div>
</figure>
</div>
<?php

next_posts_link( 'Older Entries', $product_posts->max_num_pages );
previous_posts_link( 'Next Entries &raquo;' );
wp_reset_postdata();
endforeach;
?>
</div>

相关内容

  • 没有找到相关文章

最新更新