Wordpress Timeline Show post Monthly


Wordpress Timeline Show post Monthly

我正在通过自定义帖子类型和类别获取数据。我添加了 12 个类别 1 月 到 12 月,1 月 有 1 帖子 二月 有 2 帖子

我在 1 月帖子中正在努力做的事情 2 个圆圈显示在左侧,我只想要一个 1 月圈子的其余部分。

你能请问我怎样才能把检查放在类别上吗?

这是网站 http://novartis.portlandvault.com/timeline/

谢谢

<div id="timeline">
    <?php
        //Define your custom post type name in the arguments
        $args = array('post_type' => 'timeline', 'order' => 'asc' );
        //Define the loop based on arguments
        $loop = new WP_Query( $args );
        //Display the contents
        while ( $loop->have_posts() ) : $loop->the_post();
        $thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'large') );
        $category = get_the_terms($id, 'timeline_categories'); 
        ?>
    <div class="timeline-item">
        <div class="timeline-icon">
            <div class="timeline-month">
                <?php echo $category[0]->name;?>
            </div>
        </div>
        <div class="timeline-content right">
            <h2>
                <?php the_title(); ?>
            </h2>
            <p>
                <?php echo the_content(); ?>
            </p>
            <div class="timeline_img">
                <img src="<?php echo $thumb; ?>" class="img-responsive">
            </div>
        </div>
    </div>
    <?php endwhile;?>
</div>
<!-- Timeline ends here -->

我不确定使用类别是最好的方法。您将自己限制为一年的数据。我建议实际使用发布日期来分隔帖子,那么您的代码可能看起来像这样。

<div id="timeline">
  <?php
    //Define your custom post type name in the arguments
    $args = array('post_type' => 'timeline', 'order' => 'asc' );
    //Define the loop based on arguments
    $loop = new WP_Query( $args );
    //Display the contents
    while ( $loop->have_posts() ) : $loop->the_post();
    $thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'large') );
    $category = get_the_terms($post->ID, 'timeline_categories'); 
    ?>
    <section id="<?php echo $post->ID; ?>">
      <?php
        if( $loop->current_post === 0 ) {
          $current_quarter = $category[0]->name; ?>
          <div class="quarterlyheading">
            <?php echo $current_quarter; ?>
            <div class="quarterlinebreak"><hr></div>
          </div>
        <?php } else {      
          $post_quarter = $category[0]->name;
          if($current_quarter != $post_quarter) { ?>
            <div class="quarterlyheading">
              <?php echo $post_quarter; ?>
              <div class="quarterlinebreak"><hr></div>
            </div>
          <?php }
        }
        $current_quarter = $post_quarter;
      ?>
      <div class="timeline-item">
        <?php
          if( $loop->current_post === 0 ) {
            $current_month = get_the_time('M'); ?>
            <div class="timeline-icon">
              <div class="timeline-month">
                <?php echo $current_month; ?>
              </div>
            </div>
          <?php } else {      
            $post_month = get_the_time('M');
            if($current_month != $post_month) { ?>
              <div class="timeline-icon">
                <div class="timeline-month">
                  <?php echo $post_month; ?>
                </div>
              </div>
            <?php }
          }
          $current_month = $post_month;
        ?>        
        <div class="timeline-content right">
          <h2>
            <?php the_title(); ?>
          </h2>
          <p>
            <?php echo the_content(); ?>
          </p>
          <div class="timeline_img">
            <img src="<?php echo $thumb; ?>" class="img-responsive">
          </div>
        </div>
      </div>
    </section>
  <?php endwhile;?>
</div>