【发布时间】:2018-06-22 12:53:01
【问题描述】:
谁能帮助我,我有使用 CPT UI 插件创建的自定义帖子类型,我将添加这样的分页: 这是我在自定义模板页面上的代码:
<div class="row">
<?php
/**
* @package Momentum
* Loop custom post type (journal)
* @see https://codex.wordpress.org/Post_Types
*/
/**
* Pagination
* @see https://stackoverflow.com/questions/41738362/how-to-include-pagination-in-a-wordpress-custom-post-type-query
*/
$paged = (get_query_var( 'paged' )) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'journal',
'showposts' => 2,
'posts_per_page' => 2,
'order' => 'DESC',
'paged' => $paged,
);
$loop = new WP_Query($args);
if ($loop->have_posts()):
while ($loop->have_posts()) : $loop->the_post();
?>
<div class="col-lg-6 content">
<div class="article">
<div class="image">
<?php
/**
* @package Momentum
* Check the featured image
* @see https://codex.wordpress.org/Post_Thumbnails
*/
if (has_post_thumbnail()) {
the_post_thumbnail( 'full', array('class' => 'img-responsiv') );
}else { ?>
<img src="<?php echo get_template_directory_uri(); ?>/assets/img/journal-1.jpg" alt="journal">
<?php
}
?>
</div>
<div class="text-content">
<div class="head-content">
<div class="title">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
</div>
<div class="excerpt">
<?php the_excerpt(); ?>
</div>
</div>
<div class="footer">
<a href="<?php the_permalink(); ?>" class="read-more pull-left">READ ENTRY</a>
<span class="date pull-right"><?php echo get_the_date(); ?></span>
</div>
</div>
</div>
</div><!-- /.col-lg-6 -->
<?php endwhile; ?>
<?php
$total_pages = $loop->max_num_pages;
if ($total_pages > 1) {
$current_page = max(1, get_query_var( 'paged' ));
echo paginate_links( array(
'base' => get_pagenum_link( 1 ) . '%_%',
'format' => 'page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => __('PREVIOUS'),
'next_text' => __('NEXT'),
) );
}
?>
<?php else: ?>
<h1>No Journal found</h1>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
</div>
分页链接工作正常 /page/2/...
问题,当点击到 page/2 时找不到页面。
我已经在 stackoverflow 上尝试了所有的回答和问题,但没有用。
【问题讨论】:
标签: php wordpress pagination