2016-01-23 81 views
0

我有一個搜索結果頁面的問題,分頁不起作用,當我想要轉到下一頁時,我被重定向到索引頁面,但網址是:www.mywebsite.com/ page/2 /?s = word ..搜索分頁wordpress

對於分頁工作的所有頁面,僅用於搜索不起作用。

這是search.php中的代碼

<?php 
/** 
* The template for displaying Search Results pages. 
*/ 

get_header(); ?> 

<?php 
    $search = isset($_GET['s']) ? $_GET['s']: null; 
    $user_filtre = ''; 
    $user_display = ''; 

    if($search){ 
     $user_filtre .= 's=' . $_GET['s'] . '&'; 
     $user_display .= 's=' . $_GET['s'] . '&'; 
    }?> 
    <div id="main-search" class="content-dark hidden-sm hidden-xs"> 
    <div class="container"> 
     <form method="get" action="<?php bloginfo('url'); ?>" accept-charset="UTF-8"> 
      <!--input name="s" id="s" type="hidden" --> 
      <div id="main-search-fields"> 
       <p class="pull-left term">Search Term:</p> 
       <input name="s" value="<?php the_search_query(); ?>"autocomplete="off" type="search"> 
      </div> 
      <div id="main-search-btn"> 
       <input class="button-green-download-big" type="submit" value="Search"> 
      </div> 
     </form> 
    </div> 
</div> 

<div class="browse-content"> 
    <div class="container"> 
     <section> 
      <div class="row"> 
       <ul>       
       <?php if(have_posts()): ?> 
       <?php while (have_posts()) : the_post(); ?>                        
         <?php include '_includes/items/item_2.php';?>             
        <?php endwhile; ?> 
        <?php endif; ?> 
       </ul> 
      </div> 
     </section> 
     <?php novavideo_theme_pagination(); ?> 
     </div> 
    </div> 
</div>  

任何人都有一個IDEEA?

item_2.php。

<div class="browse-movie-wrap col-xs-10 col-sm-4 col-md-5 col-lg-4"> 
      <a href="<?php the_permalink(); ?>" class="browse-movie-link"> 
       <figure> 
        <?php if($values = get_post_custom_values("poster_url")) { ?> 
        <img class="img-responsive" src="<?php echo $values[0]; ?>" alt="<?php the_title();?> Watch Online" width="210" height="315"> 
        <?php } ?> 
        <figcaption class="hidden-xs hidden-sm"> 
         <span class="fa fa-star icon-color"></span> 
         <h4 class="rating"><?php $rating = get_post_custom_values("imdbRating"); echo $rating[0]; ?>/10</h4> 
         <h4> 
          <?php $categories = get_the_category(); 

          if (! empty($categories[0])) { 
           echo esc_html($categories[0]->name); 
          } 
          ?> 
         </h4> 
         <h4 class="quality-button"><span class="fa fa-play-circle"></span> <?php $terms_as_text = strip_tags(get_the_term_list($wp_query->post->ID, 'quality', '', ', ', '')); echo $terms_as_text;; ?></h4> 
         <span class="button-green-download-big margin-button">Open Movie</span> 
        </figcaption> 
       </figure> 
      </a> 
      <div class="browse-movie-bottom"> 
       <a href="<?php the_permalink(); ?>" class="browse-movie-title"><?php $title = get_post_custom_values("Title"); echo $title[0]; ?></a> 
        <div class="browse-movie-year"><?php      $terms = wp_get_post_terms($post->ID, 'release-year', array("fields" => "all"));      if (! empty($terms) && ! is_wp_error($terms)){       foreach ($terms as $term_single) {        $term_link = get_term_link($term_single);        echo $term_single->name;                }      }      ?></div> 
      </div> 
     </div> 

回答

0

搜索結果通過query_posts實例化,並控制每頁有多少結果。在你的代碼,它可能通過包括髮生:/_includes/search-template.php但如果不是,設置它是這樣的:

// 1- Created a paged variable that knows how many paginated pages exist (depends on your site) 
$paged = get_query_var('paged') ? get_query_var('paged') : 1; 

// 2- Pass `paged` into array of arguments for query_posts 
$args = array(
    'posts_per_page' => 20, 
    'order'   => 'DESC', 
    'paged'   => $paged, 
); 

// 3- Submit query_posts to WordPress with arguments set 
query_posts($args); 

現在你可以使用next_posts_link();顯示分頁的頁面鏈接。只需將theme_pagination();的引用替換爲next_post_link();,它應輸出正確的結果。

如果要將所有邏輯抽象出您的模板,請檢查pre_get_posts。這是一種不同的方法,你可以將所有這些邏輯放入functions.php,但會達到類似的結果。

+0

不工作。當我想要轉到第2,3頁時,仍然將其重定向到主頁。 –

+0

如果您要我爲您調試代碼,則必須清除所有這些包含文件。我無法分辨錯誤來自哪裏。 – staypuftman

+0

我編輯了帖子,我關閉了search-template include,並且在那裏放了item_2.php。這個問題很奇怪,因爲在localhost和其他網站上完美地工作。 –