2016-05-14 87 views
0

嘗試按自定義分類術語和默認文章按類別分頁自定義文章類型,但它不起作用。我是WordPress的新手,我做了大量的谷歌搜索,沒有找到解決我的問題的詳細解決方案。WordPress分頁不能處理自定義文章類型和分類術語

如果有人知道請分享您的答案,這真的很感激。

注:我創建了一個自定義主題。

這裏是我的分類法product_category.php頁面代碼:

<?php get_header();?> 

<div class="container-fluid pages"> 
<div class="container" style="margin-top: 10%;"> 
    <div class="row"> 
    <div class="col-sm-8"> 
     <div class="panel panel-default"> 
      <?php $term = get_queried_object(); 
      $taxonomy = get_taxonomy($term->taxonomy); 

      ?> 
      <div class="panel-heading"><h4><?php echo 'محصولات : '.$term- >name;?></h4></div> 
      <div class="panel-body"> 
       <?php 

       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
        $args = array('post_type'=>'my_product', 
         'taxonomy'=>$taxonomy->name, 
         'posts_per_page'=> 1, 
         'term'=>$term->slug, 
         'paged'=>$paged); 

        $query = new WP_Query($args); 
       if ($query->have_posts()) { 
        while ($query->have_posts()): $query->the_post(); ?> 
         <div class="thumbnail"> 
          <?php if (has_post_thumbnail()) { 
           the_post_thumbnail('featured'); 
          } ?> 
          <div class="caption caption-content"> 
           <h3 class="product-name"><?php the_title(); ?></h3> 
           <p class="text-muted"> 
            <!-- <strong>نویسنده:</strong> <?php  //the_author();?> --> 
            &nbsp;&nbsp; تاریخ: <?php the_date(); ?> </p> 
           <p> <?php the_excerpt(); ?> </p> 
           <div> 
            <p class="price-box"> 
             <i class="fa fa- circle">&nbsp;&nbsp;&nbsp;</i>قیمت: 
             <?php if (the_field('price') == '')  { 
              // echo "00.00"; 
             } else { 
              the_field('price'); 
             } ?> 
            </p> 

           </div> 
          </div> 
          <hr> 
         </div> 
        <?php endwhile; 
       } 
       else { 
        echo '<h3>هیچ موردی درین بخش یافت نشد.</h3>'; 
       } 
       ?> 

       <!-- pagination here --> 
       <p> 

         <nav> 
          <?php if (function_exists('custom_pagination' )) { 
           custom_pagination($custom_query- >max_num_pages,"", $paged); 
          } ?> 
         </nav> 

       <?php wp_reset_postdata(); ?> 
       </p> 

      </div> 

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

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

當我點擊下頁它重定向我的索引頁面,網址仍然是:​​ http://localhost/goldsotre/product_category/ring/page/2/ Custom_pagination功能:

function custom_pagination($numpages = '', $pagerange = '', $paged='') { 

if (empty($pagerange)) { 
    $pagerange = 2; 
} 
global $paged; 
if (empty($paged)) { 
    $paged = 1; 
} 
if ($numpages == '') { 
    global $wp_query; 
    $numpages = $wp_query->max_num_pages; 
    if(!$numpages) { 
     $numpages = 1; 
    } 
} 
$pagination_args = array(
    'base'   => get_pagenum_link(1) . '%_%', 
    'format'   => 'page/%#%', 
    'total'   => $numpages, 
    'current'   => $paged, 
    'show_all'  => False, 
    'end_size'  => 1, 
    'mid_size'  => $pagerange, 
    'prev_next'  => True, 
    'prev_text'  => __('&laquo;'), 
    'next_text'  => __('&raquo;'), 
    'type'   => 'plain', 
    'add_args'  => false, 
    'add_fragment' => '' 
); 

$paginate_links = paginate_links($pagination_args); 

if ($paginate_links) { 
    echo "<nav class='custom-pagination'>"; 
    echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> "; 
    echo $paginate_links; 
    echo "</nav>"; 
} 
+0

您可以嘗試刪除空間,也請粘貼您的自定義分頁功能 $ custom_query-> max_num_pages到$ custom_query-> max_num_pages –

回答

1

機會是posts_per_page得到了由博客頁面覆蓋顯示最多價值。

我假設你正在使用的paginate_link()功能,試試這個在functions.php

add_action('pre_get_posts', function($query) 
{ 
    if ($query->is_tax('product_category')) { 
     $query->set('posts_per_page', 1); 
    } 
}); 

確保product_category是歸檔頁面的分類。 This article也許對你有幫助。

1

如果我使用下面的函數而不是我可以看到分頁鏈接,但不工作,當點擊下一個鏈接,我得到404頁。

$big = 999999999; 
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 
'format' => '?paged=%#%', 
'current' => max(1, get_query_var('paged')), 
'total' => $query->max_num_pages)); 
相關問題