WordPress分页问题

时间:2020-06-10 13:46:15

标签: wordpress custom-wordpress-pages

这是分页代码,不适用于自定义Wordpress帖子类型。我希望此分页功能正常工作。

if(!function_exists('wpex_pagination')){

function wpex_pagination() {

    $prev_arrow = is_rtl() ? '→' : '←';
    $next_arrow = is_rtl() ? '←' : '→';

    global $wp_query;
    $total = $wp_query->max_num_pages;
    $big = 999999999; // need an unlikely integer
    if( $total > 1 )  {
         if( !$current_page = get_query_var('paged') )
             $current_page = 1;
         if( get_option('permalink_structure') ) {
             $format = 'page/%#%/';
         } else {
             $format = '&paged=%#%';
         }
        echo paginate_links(array(
            'base'          => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format'        => $format,
            'current'       => max( 1, get_query_var('paged') ),
            'total'         => $total,
            'mid_size'      => 3,
            'type'          => 'list',
            'prev_text'     => $prev_arrow,
            'next_text'     => $next_arrow,
         ) );
    }
}

}

自定义POST模板

<?php
/Template Name: News/
get_header();
query_posts(array(
   'post_type' => 'news'
)); ?>
<?php
while (have_posts()) : the_post(); ?>
<?php echo get_the_date('F j, Y')?> - <?php echo the_time('H:i a');?>
<p><?php get_template_part( 'template-parts/content-single', get_post_format() );?></p>
<hr/>
<?php endwhile;?>
<?php wpex_pagination(); ?>

<?php
get_footer();
?>

0 个答案:

没有答案
相关问题