2017-08-12 123 views
0

我從頭開始構建WordPress主題,我想在博客頁面上顯示分頁,但它不起作用。不顯示Wordpress分頁

,這裏是我的index.php

<?php get_header();?> 

<div class="container-fluid" style="position: relative;"> 
    <div class="row" style="display: flex; background-color: #F5F5F5;"> 
     <div class="page-content col-md-9"> 
      <div style="padding:0 80px"> 
       <?php while (have_posts()):the_post(); ?> 
        <div class="col-md-4"> 
         <div class="thumbnails"> 
          <div class="date"> 
           <div class="day"> 
            <?php the_time('d'); ?> 
           </div> 
           <div class="month"> 
            <?php the_time('F'); ?> 
           </div> 
          </div> 
          <img src=<?php the_post_thumbnail_url(); ?> alt="" width="400" height="300"> 
          <div class="thumb-text"> 
           <div class="excerpt"><?php the_excerpt(); ?></div> 
           <a href=<?php the_permalink(); ?> target="_blank"><?php the_title(); ?></a> 
          </div> 
         </div> 
        </div> 
       <?php endwhile ?> 
      </div> 
      <div><?php wp_numeric_posts_nav(); ?></div> 
     </div> 
    </div> 
</div> 

<?php get_footer();?> 

我甚至試圖把funtion調用進入死循環,但仍然沒有工作 任何幫助或線索?

回答

0

添加此功能,您的functions.php

function theme_pagination($pages = '', $range = 3) 
{ 

     global $wp_query; 
     if (get_query_var('paged')) { $paged = get_query_var('paged'); } 
     elseif (get_query_var('page')) { $paged = get_query_var('page'); } 
     else { $paged = 1; } 

     $showitems = ($range * 2)+1; 

     if(empty($paged)) $paged = 1; 

     if($pages == '' && $pages != 0) 
     { 
     global $wp_query; 
     $pages = $wp_query->max_num_pages; 
     if(!$pages) 
     { 
      $pages = 1; 
     } 
    } 

    if(1 != $pages) 
    { 
     echo "<div class='pagination'>"; 
     if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>"; 
     if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>"; 

     for ($i=1; $i <= $pages; $i++) 
     { 
      if (1 != $pages &&(!($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems)) 
      { 
       echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>"; 
      } 
     } 

     if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>"; 
     if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>"; 
     echo "</div>\n"; 
    } 

} 

它添加到的index.php global $wp_query;頂部

,並使用theme_pagination($wp_query->max_num_pages);代替wp_numeric_posts_nav();

+0

謝謝!有效 –

0

要顯示在博客頁面分頁,你必須使用此功能:

<?php the_posts_pagination(array(
     'mid_size' => 2, 
     'prev_text' => 'Previous', 
     'next_text' => 'Next' 
    )); 
?>