2017-07-07 73 views
0

我有一個問題,只顯示我的Wordpress頁面上的編號分頁。沒有編號的分頁自定義文章類型

<?php 
/** 
* Template Name: Sale template 
*/ 
?> 
<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 

$args = array(
    'post_type' => array(
     'houten_vloeren', 'keramische_tegels', 'natuursteen_vloeren', 'tegels', 'laminaat', 'pvc_vloeren', 'tafels_stoelen', 

    ), 
    'posts_per_page' => 5, 
    'post_status' => 'publish', 
    'paged' => $paged, 
    'meta_query' => array(
     'key' => 'prijsknaller', 
     'value' => '1', 
     'compare' => '==', 
     //'type' => 'date', 
    ), 
); 
$query = new WP_Query($args); 
?> 

<div class="container"> 
    <div class="row"> 
     <div class="col-md-12"> 
      <div class="row"> 
       <div class="product-overview"> 

        <?php if ($query->have_posts()) : 
         while ($query->have_posts()) : $query->the_post(); ?> 
          <div class="col-md-3"> 
           <div class="featured-block"> 
            <div class="featured-block-image"> 
             <a href="<?php the_permalink(); ?>"><img src="<?php the_field('productafbeelding'); ?>" 
                       alt="<?php the_title(); ?>"></a> 
            </div> 
            <div class="featured-block-info"> 
             <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4> 
             <?php if (get_field('prijs_oud')) : ?> 
              <span class="oud"><?php the_field('prijs_oud'); ?></span> 
             <?php endif; ?> 
             <span class="nieuw"><?php the_field('prijs_nieuw'); ?></span> p/m<sub>2</sub> 
            </div> 
           </div> 
          </div> 

         <?php endwhile; ?> 
        <?php endif; ?> 
        <?php the_posts_pagination(array(
         'prev_text' => '&laquo;', 
         'next_text' => '&raquo;', 
        )); ?> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

查詢返回約70個產品,所以我期望它至少顯示7個數字。但是,它沒有顯示任何分頁。

+0

多少職位被查詢返回的? – Regolith

+0

只有70個產品 – idontknow

回答

0

如果您提供完整的代碼,將更容易找出您的問題。

可能是你使用wp_reset_postdata();在the_posts_pagination()之前;

請檢查。

+0

好吧,我會更新我的openspost,其中包括整個代碼。 – idontknow

0

試試這個代碼,它肯定幫助您

 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;  

$args = array(
    'post_type'  => array (
         'houten_vloeren', 'keramische_tegels', 'natuursteen_vloeren', 'tegels', 'laminaat', 'pvc_vloeren', 'tafels_stoelen', 

         ), 
    'posts_per_page' => 5, 
    'post_status' => 'publish',  
    'paged'   => $paged, 
    'meta_query'  => array (
          'key' => 'prijsknaller', 
          'value' => '1' , 
          'compare' => '==', 
          //'type' => 'date', 
          ), 
    ); 
$wp_query = new WP_Query($args); 
+0

請添加關於您更改的內容以及爲什麼/如何工作的解釋。 更多信息[here](https://stackoverflow.com/help/how-to-answer)。 – NaeiKinDus

+0

不幸的是,它沒有工作。我更新了我的開場白。 – idontknow

+0

有時,wordpress無法識別它們是否是wp_query中的直接查詢,所以試圖將代碼放在單獨的變量中有助於。因此,爲什麼我使用了$ args,並在wp_query中使用了它。 –

0

這種替換代碼:

<?php 
/** 
* Template Name: Sale template 
*/ 
?> 
<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
if ($paged == "1") { 
    $args = array(
    'post_type' => array(
     'houten_vloeren', 'keramische_tegels', 'natuursteen_vloeren', 'tegels', 'laminaat', 'pvc_vloeren', 'tafels_stoelen', 

    ), 
    'posts_per_page' => 5, 
    'post_status' => 'publish', 
    'paged' => $paged, 
    'offset' => 0, 
    'meta_query' => array(
     'key' => 'prijsknaller', 
     'value' => '1', 
     'compare' => '==', 
     //'type' => 'date', 
    ), 
); 
} else { 
    $offset = $paged * 5; 
    $offset = $offset - 5; 
    $args = array(
    'post_type' => array(
     'houten_vloeren', 'keramische_tegels', 'natuursteen_vloeren', 'tegels', 'laminaat', 'pvc_vloeren', 'tafels_stoelen', 

    ), 
    'posts_per_page' => 5, 
    'post_status' => 'publish', 
    'paged' => $paged, 
    'offset' => $offset, 
    'meta_query' => array(
     'key' => 'prijsknaller', 
     'value' => '1', 
     'compare' => '==', 
     //'type' => 'date', 
    ), 
); 
} 

$query = new WP_Query($args); 
?> 

<div class="container"> 
    <div class="row"> 
     <div class="col-md-12"> 
      <div class="row"> 
       <div class="product-overview"> 

        <?php if ($query->have_posts()) : 
         while ($query->have_posts()) : $query->the_post(); ?> 
          <div class="col-md-3"> 
           <div class="featured-block"> 
            <div class="featured-block-image"> 
             <a href="<?php the_permalink(); ?>"><img src="<?php the_field('productafbeelding'); ?>" 
                       alt="<?php the_title(); ?>"></a> 
            </div> 
            <div class="featured-block-info"> 
             <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4> 
             <?php if (get_field('prijs_oud')) : ?> 
              <span class="oud"><?php the_field('prijs_oud'); ?></span> 
             <span class="nieuw"><?php the_field('prijs_nieuw'); ?></span> p/m<sub>2</sub> 
            </div> 
           </div> 
          </div> 

         <?php endwhile; ?> 
        <div class="pagination-grp"> 
         <?php 
         $big = 999999999; // need an unlikely integer 
         //$i=1; 

         echo paginate_links(array(
          'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 
          'format' => '?paged=%#%', 
          'current' => max(1, get_query_var('paged')), 
          'prev_text' => __('<'), 
          'next_text' => __('>'), 
          'total' => $loop->max_num_pages 

         )); 
         wp_reset_postdata(); 
         endif; 
         ?> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 
+0

謝謝,但這是無效的PHP代碼。我修復了你的php,但是.pagination-grp div仍然是完全空的。 – idontknow

相關問題