2016-07-26 8 views
0

私はindex.phpファイル内の3つの投稿をすべて行divに追加したいのですが、最初の投稿を除外して、最初の投稿は異なっています。wordpressはループ内の最初の投稿の後に1つのdiv内の3つの投稿をすべてラップします

私は現在、ループはすべての3つの記事のために働いてきたが、私はそれ特集記事

以下

は私のコード

<div class="content post-main__content clearfix" id="post-<?php the_ID(); ?>" > 
<?php 
if(have_posts()) : for($count=0;have_posts();$count++) : the_post(); 
    $open = !($count%3) ? '<div class="post-main__row clearfix">' : ''; //Create open wrapper if count is divisible by 3 
    $close = !($count%3) && $count ? '</div>' : ''; //Close the previous wrapper if count is divisible by 3 and greater than 0 
    echo $close.$open; 


?> 
<div class="post-main__cell"> 
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Click to go to <?php the_title(); ?>"> 
     <div class="post-main__cell-top"> 
      <?php the_post_thumbnail(array(330, 167,)); ?> 
      <h3 class="content__category-name <?php foreach((get_the_category()) as $category) { echo $category->cat_name. ''; } ?>"> 
       <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?> 
      </h3> 
     </div> 
     <div class="post-main__cell-bottom"> 
      <h2 class="archive-header"><?php the_title() ?></h2> 
      <p class="paragraph--time"><?php posted_on(); ?></p> 
     </div> 
    </a> 
</div> 
<?php endfor; else : ?> 
であることを確認するために、異なる最初の投稿を最初のポストとスタイルを除外したいと思います
<?php echo $count ? '</div>' : ''; //Close the last wrapper if post count is greater than 0 ?> 

答えて

0

私はこの

<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
$args = array('posts_per_page' => 12, 'paged' => $paged); 
query_posts($args); ?> 

<?php if (have_posts()) : ?> 
<?php $postcount = 0; ?> 
<?php while (have_posts()) : the_post(); ?> 
<?php $postcount++; ?> 

<?php if ($postcount == 1 && $paged == 1) : // if this is the first post & first page ?> 
<div class="post-main__row clearfix"> 
    <div class="post-main__cell post-main__cell-large"> 
     <a href="<?php the_permalink() ?>" rel="bookmark" title="Click to go to <?php the_title(); ?>"> 
      <div class="post-main__cell-left clearfix"> 
       <?php the_post_thumbnail(array(691, 317,)); ?> 
       <h3 class="content__category-name <?php foreach((get_the_category()) as $category) { echo $category->cat_name. ''; } ?>"> 
        <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?> 
       </h3> 
      </div> 
      <div class="post-main__cell-right"> 
       <h2 class="archive-header"><?php the_title() ?></h2> 
       <p class="paragraph--time"><?php the_time('l, F jS, Y') ?></p> 
      </div> 
     </a> 
    </div> 
</div> 
<?php 
if(have_posts()) : for($count=0;have_posts();$count++) : the_post(); 
    $open = !($count%3) ? '<div class="post-main__row clearfix">' : ''; //Create open wrapper if count is divisible by 3 
    $close = !($count%3) && $count ? '</div>' : ''; //Close the previous wrapper if count is divisible by 3 and greater than 0 
    echo $close.$open; 
?> 
<div class="post-main__cell"> 
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Click to go to <?php the_title(); ?>"> 
     <div class="post-main__cell-top"> 
      <?php the_post_thumbnail(array(330, 167,)); ?> 
      <h3 class="content__category-name <?php foreach((get_the_category()) as $category) { echo $category->cat_name. ''; } ?>"> 
       <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?> 
      </h3> 
     </div> 
     <div class="post-main__cell-bottom"> 
      <h2 class="archive-header"><?php the_title() ?></h2> 
      <p class="paragraph--time"><?php the_time('l, F jS, Y') ?></p> 
     </div> 
    </a> 
</div> 
<?php endfor; else : ?> 
<?php endif; ?> 
<?php echo $count ? '</div>' : ''; //Close the last wrapper if post count is greater than 0 ?> 
<?php endif; ?> 
<?php endwhile; ?> 
と同じように働いていました
関連する問題