2013-07-10 1 views
0

내가 뭘하려고 타임 라인을 만드는 것입니다. 내가 원하는 것은 매월 첫 번째 게시물 상단에 날짜를 표시하는 것입니다. 따라서 아래 게시물이 이번 달에 있음을 알기 위해 구분 기호와 같은 역할을합니다. 표시 내용이

현재 난 그냥 카테고리에있는 모든 게시물을 조회하고 있습니다. 이제 내가 원하는 것은 if else 문입니다. 그것의 달의 첫번째 포스트 인 경우에, 몇몇 원본을 되풀이하십시오. 제가 어떻게 이렇게 내가 편집하고 마무리했다 처음 수행되기 전에

<?php $cat=get_field('time_taxonomy');?> 
       <?php global $post; $i=0; $args=array('numberposts'=>-1, 'offset'=> 0, 'category' => $cat); $myposts = get_posts($args); foreach($myposts as $post) : if ($i==1) { } else {}; setup_postdata($post); $i++; ?> 
       <div class="ss-container"> 
       <div class="none"><?php echo date("F"); ?></div> 
        <div class="ss-row"> 
         <div class="ss-left"> 
          <h2 id="month"><?php echo date("F"); ?></h2> 
         </div> 
         <div class="ss-right"> 
          <h2><?php echo date("Y"); ?></h2> 
         </div> 
        </div> 
        <div class="ss-row ss-medium"> 
         <!-- Pulling in the featured post imgae and title--> 
         <?php $image=wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'timeline'); ?> 
         <div class="ss-left"> 
          <a href="<?php the_permalink(); ?>" class="ss-circle"> 
           <img class="ss-circle-1" src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" /> 
          </a> 
         </div> 
         <div class="ss-right"> 
          <h3> 
           <span><?php echo date("F j, Y | g:i a"); ?></span> 
           <a href="#"> 
            <?php the_title(); ?> 
           </a> 
          </h3> 
         </div> 
        </div> 
       </div> 
       <?php endforeach; ?> 

답변

0
<?php $cat=get_field('time_taxonomy');?> 
       <?php global $post; $i=0; $args=array('numberposts'=>-1, 'offset'=> 0, 'category' => $cat); $myposts = get_posts($args); $prev_month = -1; foreach($myposts as $post) : 
        $post_month = date("m",strtotime($post["post_date"])); 
        if($post_month != $prev_month) { 
         // First post of the new month 
        } else { 
         // Still the same month 
        } 
        $prev_month = $post_month; 
        setup_postdata($post); $i++; ?> 
       <div class="ss-container"> 
       <div class="none"><?php echo date("F"); ?></div> 
        <div class="ss-row"> 
         <div class="ss-left"> 
          <h2 id="month"><?php echo date("F"); ?></h2> 
         </div> 
         <div class="ss-right"> 
          <h2><?php echo date("Y"); ?></h2> 
         </div> 
        </div> 
        <div class="ss-row ss-medium"> 
         <!-- Pulling in the featured post imgae and title--> 
         <?php $image=wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'timeline'); ?> 
         <div class="ss-left"> 
          <a href="<?php the_permalink(); ?>" class="ss-circle"> 
           <img class="ss-circle-1" src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" /> 
          </a> 
         </div> 
         <div class="ss-right"> 
          <h3> 
           <span><?php echo date("F j, Y | g:i a"); ?></span> 
           <a href="#"> 
            <?php the_title(); ?> 
           </a> 
          </h3> 
         </div> 
        </div> 
       </div> 
       <?php endforeach; ?> 
+0

미안 해요, 난 실수로 답을 게시, WP_Query의 오류가) 것과 –

+0

그냥 하나의 작은 수정을했다 $ prev_month = -1; foreach ($ myposts를 $ post) :?> –

관련 문제