2017-11-27 11 views
0

저는 맞춤 검색을 위해 the_posts_pagination 또는 다른 출력 숫자 게시물 탐색을 만드는 방법을 찾으려고합니다.Wordpress 게시물 쿼리가 작동하지 않습니다.

했지만 작동하지 않는 것, 나는 아무 잘못이 사전에 제안과 솔루션 덕분에 고맙게 생각하고있는 중이 야 경우 모르겠어요

내 코드 그렇게하기 위해

<?php global $query_string; // required 
$posts = query_posts($query_string.'&posts_per_page=3&order=ASC'); ?> 

    <div class="main-post-loop"> 
     <div class="big-thum-section img-is-responsive"> 
      <?php if (has_post_thumbnail()) : ?> 
      <?php the_post_thumbnail('small-block-thumb'); ?> 
       <?php endif; ?> 
     </div> 

     <div class="squiggle-post-meta-section clearfix"> 
      <h2><a href="<?php echo get_permalink(); ?>"> <?php the_title(); ?> </a></h2> 
      <div class="excerpt-post"><?php the_excerpt(); ?></div> 
     </div> 
     <div class="continue-reading-section"> 
     <a href="<?php echo get_permalink(); ?>" class="cont-reading"> Continue reading <i class="fa fa-chevron-right"></i></a> 
     </div> 
     <div class="squiggly-line"></div> 
    </div> 
    <?php 
     the_posts_pagination(array(
      'mid_size' => 2, 
      'prev_text' => esc_html('&larr;'), 
      'next_text' => esc_html('&rarr;'), 
      )); 
?> 
<?php wp_reset_query(); // reset the query ?> 

답변

1

몇 단계 만 거치면됩니다. 먼저, wp-pagenavi 플러그인을 사용하는 것이 좋습니다. 많은 것들을 처리합니다.

어떤 방법, 내가와 플러그인없이 두 가지를 설명, 먼저 우리는 우리의 쿼리를 작성하고 paged 속성을 설정 paged 쿼리 VAR에 따라, 그래서 사용자가 탐색 할 때 예제 페이지 3를 들어, 쿼리는 게시물을 필터링 할 수

$paged = (int) (get_query_var('paged') ?: (get_query_var('page')?: 1)); 
$my_query = new WP_Query(array(
    'posts_per_page' => 10, 
    'paged'   => $paged // This is important for pagination links to work 
)); 

당신이 wp-pagenavi 플러그인을 사용하기로 결정했다면 지금, 그것은 사용자 정의 쿼리 paginations을하는 것은 매우 쉽습니다, 당신이 할 필요가있다 :

<?php if(function_exists('wp_pagenavi')) wp_pagenavi(array('query' => $my_query)); ?> 
와 세 번째 페이지 게시물을 보여줍니다3210

하지만 the_posts_pagination() 기능을 사용하고자하는 경우, 나는 그것을 사용자 정의 쿼리를 지원하는지 모르겠지만, 그것은 paginate_links() 기능을 사용하고 있기 때문에,이 인수

$args = array(
    'current' => max(1, $paged), // $paged is what we defined earlier or you can use just get_query_var('paged') 
    'total' => $my_query->max_num_pages 
) 

그렇지 않은 경우에 작동합니다, 위의 동일한 인수를 사용하여 paginate_links() 함수 자체를 사용할 수 있습니다.

도 참조 : functions.php에서 this answer

+0

덕분에, 매김 didnt 한의 CME하지만 위로, 모든 제안을 시도했지만 아무 소용이 없음 –

+0

@NeonEmmanuel 쿼리의 게시물 개수,'$ paged' 변수,'$ my_quer y-> max_num_pages', ... 뭔가 잘못되었는지 확인하려면,'var_dump'를 사용하여 변수를 테스트하십시오. – Amin

1
<?php 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    query_posts(array('post_type' => 'post', 'order' => 'ASC', 'paged' => $paged, 'posts_per_page' => 12)); 
     if(have_posts()) : ?> 
      <?php while (have_posts()) : the_post(); ?> 
       <?php the_title();?> 
       <?php the_excerpt(); ?> 
      <?php endwhile; ?> 
      <div class="pagination"><?php my_pagination(); ?></div> 
     <?php endif; ?> 
<?php wp_reset_query(); ?> 

추가,

if (! function_exists('my_pagination')) : 
    function my_pagination() { 
     global $wp_query; 

     $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' => $wp_query->max_num_pages 
     )); 
    } 
endif; 

또는 이 시도 : 당신의 시간을 @amin http://www.wpbeginner.com/wp-themes/how-to-add-numeric-pagination-in-your-wordpress-theme/

+0

감사합니다, 감사합니다. 감사합니다. –