2017-10-26 2 views
1

카테고리 이름이있는 맞춤형 홈페이지를 만들었습니다. 카테고리를 클릭하면 "page-category.php"라는 다른 페이지로 리디렉션되고 UR1에 카테고리 ID가 전달됩니다. page-category.php 페이지에서 ID를 캡처하고 사진으로 사용자 정의 된 포스트 디자인을 표시하고 특정 카테고리를 발췌했습니다. 그러나 게시물의 수가 특정 숫자를 초과하는 경우 내 페이지에서 페이지 매김을 원합니다. 페이지 매기기 기능이 제대로 작동하지 않습니다. 나는 내가 "wwww.example.com?id=108"같은 URL을 전송하고있는 범주 옵션을 클릭 function.php.When 아무것도 추가하지 않은WordPress의 페이지 매김이 작동하지 않습니다.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
$npsPosts = new WP_Query('posts_per_page=5&cat='.$cat_id.'&paged=' . $paged); 
      if($npsPosts -> have_posts()): 

     next_posts_link('Older Entries', $the_query->max_num_pages); 
     previous_posts_link('Newer Entries'); 

      <?php 
       while($npsPosts->have_posts()): $npsPosts ->the_post(); 
        if (!in_array($post->ID, $do_not_duplicate)) { ?> 
         <div class="horizontal_post_grid_row_col cat-page-box"> 
          <div class="horizontal_post_grid_row_col-img"> 
           <a href='<?php the_permalink();?>'><?php the_post_thumbnail('medium-thumbnail'); ?></a> 
          </div> 
          <div class="horizontal_post_grid_row_col_content"> 
           <h3 style="margin-bottom:5px;"><a href='<?php the_permalink();?>'><?php the_title();?></a></h3> 
           <span class="author_tag">Reading time : <?php echo reading_time(); ?></span> 
           <div class="excerpt_content"><?php the_excerpt(); ?></div> 
           <div class='keep_reading_text'><a href='<?php the_permalink();?>'>Read more</a></div> 
          </div> 
         </div> 
         <div class="gap-cat">jkn</div> 


        <?php 
       } 
       endwhile; 

         next_posts_link('Older Entries', $the_query->max_num_pages); 
      previous_posts_link('Newer Entries'); 
    else: 
      endif; 

: 여기 내 코드입니다. 나는 page-category.php에서 ID를 잡아 내고 그 카테고리 ID의 모든 게시물을 표시합니다. URL은 "www.example.com/category/?id=108"이됩니다. 페이지 매김을 사용할 때 "www.example.com/category/page/2/?id=108"이됩니다. 올바른 방법이 아니라면 제안하십시오.

답변

0

제거 기능 next_posts_link, previous_posts_link 코드 아래에 추가 :

$big = 999999999; // need an unlikely integer 

echo paginate_links(array(
    'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 
    'format' => '?paged=%#%', 
    'current' => max(1, get_query_var('paged')), 
    'total' => $npsPosts->max_num_pages 
)); 
+0

내 URL은 "http://example.com/category/page/2/?id=108"와 같은오고있다. 그리고 그것은 페이지에 아무것도 보여주지 않습니다. 카테고리 옵션에서 URL을 클릭 할 때 내 ID를 얻는 방법이 올바르지 않습니다. – UDGogs

+0

@UditGogoi URL 시도 : example.com/category/?id=108&page=2 – vrajesh

+0

어떤 URL을이 위치로 바꿔야합니까? 페이지 매김이있는 페이지에있는 경우 페이지 매기기 코드의 매개 변수를 어디에서 제공합니까? 나는 장소가 보이지 않는다. – UDGogs

관련 문제