我对我的自定义帖子类型“网站”进行了查询。我正在尝试使分页正常工作,但出现了一些错误。我认为整个代码都是可以的,只有结尾之前的部分while标记。我只是不知道怎么做才对。任何帮助都将不胜感激!
<?php
// WP_Query arguments
$args = array (
\'post_type\' => \'website\',
\'post_status\' => \'publish\',
\'pagination\' => true,
\'posts_per_page\' => \'5\',
\'posts_per_archive_page\' => \'5\',
\'ignore_sticky_posts\' => false,
\'order\' => \'DESC\',
);
// Get current page and append to custom query parameters array
$mfs_query[\'paged\'] = get_query_var( \'paged\' ) ? get_query_var( \'paged\' ) : 1;
// The Query
$mfs_query = new WP_Query( $args );
// Pagination fix
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $mfs_query;
// The Loop
if ( $mfs_query->have_posts() ) {
while ( $mfs_query->have_posts() ) {
$mfs_query->the_post();
// do something
?> <div class="submission">
<a class="submission-thumb" href="<?php echo get_permalink(get_the_ID()); ?>">
<?php echo the_post_thumbnail(); ?>
</a>
<a class="submission-title" href="<?php echo get_permalink(get_the_ID()); ?>">
<h3><?php the_title(); ?></h3> <span class="posted-ago"><?php echo human_time_diff( get_the_time(\'U\'), current_time(\'timestamp\') ) . \' ago\'; ?></span>
</a>
<a class="submission-link" href="<?php the_field(\'site_url\'); ?>" target="_blank">Visit</a>
</div>
<?php } ?>
<?php endwhile; else : ?>
<?php wp_reset_postdata(); ?>
<p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php // Custom query loop pagination
previous_posts_link( \'Older Posts\' );
next_posts_link( \'Newer Posts\', $mfs_query->max_num_pages ); ?>
<?php $wp_query = null; $wp_query = $temp_query;?>
?>