2017-02-15 52 views
1

我想知道是否有任何方法可以使用WordPress的郵政計數器顯示每個使用相同的CSS類的最多10個帖子,我已經在下面的代碼中做了一個,但它只顯示兩個,當我發了帖子4,它不遵守我創建的CSS規則。 這是我走了多遠。WordPress的後循環任何人?

<div class="col-md-12 featt big-grid"> 
<div class="container-fluid no-padding"> 
    <?php 
    $args = array(
    'post_type' => '', 
    'category_name' => '', 
    'posts_per_page' => '2' 
); 
    $query = new WP_Query($args); 
    if ($query->have_posts()) : 
    $i = 0; 

    while($query->have_posts()) : 
     $query->the_post(); 
    $i++; 
     if($i <= 2) { 
      if($i == 1) { 
    ?> 
      <div class="big-pane col-xs-6"> 
      <div class="the-big-pane image"> 
      <?php the_post_thumbnail();?> 
      </div> 
      <div class="big-pane overlay"> 

       <div class="the-big-pane-content"> 
       <div class="the-cont-cat"> 
    <span class="the-content-cat-bt"> <?php $category = get_the_category(); if ($category) 
       { echo wp_kses_post('<a href="' . get_category_link($category[0]->term_id) . '" class="tiptipBlog" title="' . sprintf(esc_html__("View all posts in %s", "acardio"), $category[0]->name) . '" ' . '>' . $category[0]->name.'</a> ');} ?></span> <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span> 
</div> 
       <h1><a href="<?php the_permalink(); ?>"><?php the_title(); echo" ".$i?></a></h1> 
       <span class="the-content-post-data"><span class="the-auth-post-image-content" style="padding-top: 0px !important;"> <?php echo get_avatar(get_the_author_meta('user_email'), 100); ?> </span> By <a href="#"><?php the_author_posts_link(); ?></a> <span class="the-content-post-date"> <i class="fa fa-clock-o the-content "></i><?php the_time('jS M, Y') ?></span> </span> 
       </div> 
      </div> 
      </div> 

      <div class="big-pane col-xs-6"> 
      <?php 
      } 
      else { ?> 
      <div class="the-big-pane image"> 
      <?php the_post_thumbnail();?> 
      </div> 
      <div class="big-pane overlay"> 

       <div class="the-big-pane-content"> 
       <div class="the-cont-cat"> 
    <span class="the-content-cat-bt"> <?php $category = get_the_category(); if ($category) 
       { echo wp_kses_post('<a href="' . get_category_link($category[0]->term_id) . '" class="tiptipBlog" title="' . sprintf(esc_html__("View all posts in %s", "acardio"), $category[0]->name) . '" ' . '>' . $category[0]->name.'</a> ');} ?></span> <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span> 
    </div> 
       <h1><a href="<?php the_permalink(); ?>"><?php the_title(); echo" ".$i?></a></h1> 
       <span class="the-content-post-data"><span class="the-auth-post-image-content" style="padding-top: 0px !important;"> <?php echo get_avatar(get_the_author_meta('user_email'), 100); ?> </span> By <a href="#"><?php the_author_posts_link(); ?></a> <span class="the-content-post-date"> <i class="fa fa-clock-o the-content "></i><?php the_time('jS M, Y') ?></span> </span> 
       </div> 
      </div> 
      </div> 

      <?php 
      if($i == 2){ ?> 
       </div> 

       <?php 
      } 
      } 
     } 


    endwhile; 
    else: 
     echo "<p>Sorry no post found :(!</p>"; 
    endif; 
    wp_reset_postdata(); ?>    
    </div>   

回答

1

您需要更改這個

$args = array(
    'post_type' => '', 
    'category_name' => '', 
    'posts_per_page' => '2' 
); 

,以反映職位的posts_per_page

$args = array(
    'post_type' => '', 
    'category_name' => '', 
    'posts_per_page' => '10' 
); 
+0

沒有工作的兄弟數,我覺得頁面計數器防止它weoking,我認爲這可以解決這個問題的理想之處在於,將後臺設置爲>(大於)兩個預定義的樣式。因此> 2,但我不知道haw去做這件事。 –