Word Press自定义查询分页不起作用

时间:2018-11-10 06:25:56

标签: wordpress custom-wordpress-pages

我在front-page.php中有此代码,我想在首页上显示自定义帖子类型的分页。我在页面底部获得了分页链接,但是这些链接导致空白页仅包含页眉和页脚而不是全部内容。怎么了?

<?php get_header(); ?>

<div class="container">
<?php

$contactsHome = new WP_Query(array(
'page' => get_query_var('page', 1),
'posts_per_page'=> 5,
'post_type'=> 'contacts',
 ));?>

<?php while($contactsHome->have_posts()){
 $contactsHome->the_post(); ?>

<h2 class="headline"><a href="<?php the_permalink();?>"><?php the_title();?>       
   </a></h2>

 <?php
  } echo paginate_links(array(
               'total' => $contactsHome->max_num_pages
   ));?>

   wp_reset_query();

  </div>
 <?php get_footer(); ?>

1 个答案:

答案 0 :(得分:0)

我正在使用分页功能。

function wp_pagination() {
global $wp_query;
$big = 12345678;
$page_format = paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
    'total' => $wp_query->max_num_pages,
    'type'  => 'array'
) );
if( is_array($page_format) ) {
    $paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
    echo '<div class ="number_paging">';
    echo '<span class ="santypage">'.'Showing '. $paged . ' of ' . $wp_query->max_num_pages .'</span>';
    foreach ( $page_format as $page ) {
            echo "<span class = 'number_page'>$page</span>";
    }
   echo '</div>';
}

}

现在在页面上调用此功能。

<?php wp_pagination(); ?>