2016-12-16 16 views
1

最近のポストをループの4番目の位置に表示したい。最近の投稿を4番目のポストに表示

たとえば、私は1〜10の投稿を持ち、10の投稿は最近の投稿です。私は4位に表示したいと思います。

ここは私のコードです。

<?php 
$blog_arg = array('post_type'=>'post','posts_per_page'=>7,'order'=>'DESC', 'orderby'=> 'most_recent',); 
$get_blogs = new WP_QUERY($blog_arg); 

if($get_blogs->have_posts()){ 
    global $post; 
    $count =1; 
    while($get_blogs->have_posts()) : $get_blogs->the_post(); 
     $category_name = wp_get_post_terms($post->ID, 'category', array("fields" => "names")); 

     if(has_post_thumbnail()){ ?> 
      <div class="blog_posts" style="background:#767b7b url(<?php the_post_thumbnail_url();?>) ; "> 
     <?php 
     }else{ 
      if($count %2 == 0){ 
       echo ' <div class="blog_posts" style="background:#909696">'; 
      }else{ 
       echo ' <div class="blog_posts" style="background:#767b7b">'; 
      } 
     } 

     if($count == 4){ 
      echo "Display Recent post heree.."; 
     } 
    ?> 

      <div class="verti-middal-main"> 
       <h3><?php echo $post->post_title;?></h3> 
       <span><?php echo $category_name[0]; ?></span> 
       <div class="blog-sort-disk"><?php echo wp_trim_words($post->post_content, 20, '');?></div> 
       <a class="read-more" href="<?php the_permalink(); ?>">READ MORE</a> 
      </div> 
      <div id="blog_loading_loader" ></div> 
     </div> 
    <?php 
    $count++; 
    endwhile; 
}?> 

最近の投稿は4位に表示されませんでしたので、最近の投稿(10個の投稿数)を4位に表示するにはどうすればよいですか。

答えて

0

位置10に10番目の要素をグラフィックで表示しますか?

もしそうなら、私の提案は、カスタム配列にとのようなもので、各ポストのすべての要素を置くことです:あなたは慎重要素の表示を制御することができ

while($get_blogs->have_posts()) : $get_blogs->the_post(); 
    $custom_array_of_posts[]['title'] = $post->post_title; 
endwhile; 
//Then you could use this array and print whenever you need 
// Using a foreach for example 

$custom_array_of_posts[10][title] //Access the title of tenth post 

このヘルプが必要です。

+0

私の投稿件数が増加している場合は、配列の値を変更するたびに増加します。 – maddy

+0

私はあなたの質問を理解していないかもしれません。 10個の投稿があり、4番目の10番目の位置に印刷しますか? –

関連する問題