2017-02-02 29 views
-1

私は別のカスタムタクソノミーに投稿しています。 1つのタクソノミーの投稿をページに表示する必要があります。今、私はすべての分類法のすべての投稿を1ページにまとめています。私はタクソノミのためにforeachループを持っています。ループの中で、そのタクソノミーに対応するすべての投稿がpostメソッドを使って表示されています。この場合、ページネーションを追加するにはどうすればよいですか?私はwordpressでページネーションを追加するには

<div class="main"> 

<section class="brands-sec product-sec"> 
<div class="container"> 
<?php 
$siteurl = home_url('/'); 
$tax = 'product'; // slug of taxonomy 
$terms = get_terms($tax); 
foreach ($terms as $term) { 
$id = $term->term_id; 
$slug = $term->slug; 
$description = $term->description; 
$image_url = z_taxonomy_image_url($id, NULL, TRUE); // category image display 
$link = "<a href='$siteurl?$tax=$slug' ><h1> $term->name </h1></a>"; 

echo '<img src="' . $image_url . '">'; ?> 
    <div class="col-md-8 pull-right col-sm-10 pull-right col-xs-12 brnd prdct"> 

     <img src="<?php echo $image_url ; ?>" class="img-responsive pdt-logo" alt="loyd"/> 

     <div class="brand-logos pdt"> 

     <p><?php echo $description ; ?></p> 

       <h4>Product</h4> 
      <?php $args = array("posts_per_page" => "-1", "product"=>$slug ,"post_type" => "products"); 
$posts = get_posts($args); 
foreach($posts as $data){ 
$thumb = wp_get_attachment_url(get_post_thumbnail_id($data ->ID)); 
$custom_fonts = get_post_custom($data->ID);$custom_fonts_key=  $custom_fonts['category'];$custom_fonts_array = $custom_fonts_key[0]; ?>      
      <div class="row mb40"> 

       <div class="col-md-4 col-sm-4 col-xs-12 brand-single product-single"> 
        <img src="<?php echo $thumb; ?>" class="img-responsive" alt="allegro products"/> 
        <h5><?php echo $data->post_title; ?></h5> 
        <p><?php echo $data->post_content; ?></p> 
       </div> 
       <div class="col-md-8 col-sm-8 col-xs-12 brand-single product-detail"> 
        <ul class="products"> 
        <?php 
    $attachments = new Attachments('my_attachments',$data->ID); /* pass the instance name */ ?> 
<?php if($attachments->exist()) : ?> 
<?php while($attachments->get()) : ?> 
        <li><img src="<?php echo $attachments->url(); ?>" class="img-responsive" alt="allegro products"/></li> 
<?php endwhile; ?> 
<?php endif; ?> 
        </ul> 


       </div> 


      </div> 
<?php } ?>    

     </div><!--end brand-logos--> 

    </div><!--end brnd--> 
    <?php } ?> 

</div> 

の下に私のコードを囲むい ここの製品は、カスタム分類です。その中には、複数の用語があります。loyd、Nycofee、...これらの用語には、複数の投稿があります。私は1ページにloydの投稿を表示し、次のページにはncofeeを表示する必要があります。この場合、ページネーションを追加する方法は?

答えて

0

これを試してみてください:

あなたはする-1あなたが希望数に

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
$args = array("posts_per_page" => "-1", "product"=>$slug ,"post_type" => "products"); 

変更それをpost_per_pageを持っています。そして

  </div> 
<?php } ?>    

     </div><!--end brand-logos--> 

<?php if (function_exists('wp_pagenavi')) wp_pagenavi(array('query' => $args)); ?> 
<?php wp_reset_postdata(); ?> 
ここ

はWordPress

<?php if (have_posts()) : ?> 

<!-- Add the pagination functions here. --> 

<!-- Start of the main loop. --> 
<?php while (have_posts()) : the_post(); ?> 

<!-- the rest of your theme's main loop --> 

<?php endwhile; ?> 
<!-- End of the main loop --> 

<!-- Add the pagination functions here. --> 

<div class="nav-previous alignleft"><?php next_posts_link('Older posts'); ?></div> 
<div class="nav-next alignright"><?php previous_posts_link('Newer posts'); ?></div> 

<?php else : ?> 
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p> 
<?php endif; ?> 
のための基本的な改ページで追加ここではPHPを終了する前に終了

'paged' => $paged 

に追加

ソース:https://codex.wordpress.org/Pagination「例題ループ付きページング」

まだ完全なリストが表示されている場合。 これを試してください:http://callmenick.com/post/custom-wordpress-loop-with-pagination

+0

完全なリストを表示します。どのように私はこれを使うことができますか? – Ranju

+0

あなたはこのURLをチェックすることができますhttp://callmenick.com/post/custom-wordpress-loop-with-pagination –

+0

私のコードを追加しました。手伝ってくれますか? – Ranju

関連する問題