Php Wordpress时间表显示每月发布

Php Wordpress时间表显示每月发布,php,css,wordpress,Php,Css,Wordpress,我通过自定义帖子类型和类别获取数据。我已经增加了12类一月至十二月和一月有1个职位二月有2个职位 我在一月邮报上努力做的是,左边显示的是2个圆圈,我只想要一个一月的圆圈,在圆圈下面是一月邮报的其余部分 请问我怎样才能在分类上打勾 这里是网站 谢谢 <div id="timeline"> <?php //Define your custom post type name in the arguments $args = array('po

我通过自定义帖子类型和类别获取数据。我已经增加了12类一月至十二月和一月有1个职位二月有2个职位

我在一月邮报上努力做的是,左边显示的是2个圆圈,我只想要一个一月的圆圈,在圆圈下面是一月邮报的其余部分

请问我怎样才能在分类上打勾

这里是网站

谢谢

<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 -->


“class=”img responsive“>
我不确定使用类别是否是最好的方法。您将自己的数据限制为一年。我建议实际使用发布日期来分隔帖子,那么您的代码可能类似于此

<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>


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

<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>


感谢Andres的回复。如果我在3月发布1月1日的帖子呢?有没有办法存储类别,然后检查帖子是否与不显示时间线图标相同,或者如果类别是新的,则显示时间线图标?这有什么意义吗?感谢Andres的回复。如果我在3月发布1月1日的帖子呢?有什么问题吗可以存储类别,然后检查帖子是否与不显示时间线图标相同,或者该类别是否是新的,而不是显示时间线图标?这有什么意义吗?嗨,我应该在该模板上添加季度月份吗?例如,第一个标题“一月-三月”位于与一月到三月相关的帖子下方,然后是四月-六月等等?我不确定我是否我理解你的问题。你是说如果你今天发布了一些东西,但想在一月份之前发布吗?你所需要做的就是更改“已发布”的内容“所以它认为这篇文章是在一月份发表的。然后,它将把它归为1月份,而不添加第二个标签。同样,这个方法不使用类别,而是使用发布日期。嗨,安德烈斯,谢谢你的回复。我想要这样的东西在顶部显示季度月份,然后在这个月内显示帖子Hey Atiff,我补充了你的“时间线”类别,我会用它来设置一月到三月的标题。所以现在,当你在你想要的组中标记帖子时,它使用了与显示/隐藏“季度标题”部分非常相似的逻辑。希望这是有意义的。嗨,我可以在这个模板上添加季度月份吗?比如第一个标题是一月到三月,然后是四月到六月等等。我不确定我是否理解你的问题。你的意思是如果你今天发布了一些东西,但想在一月份之前发布?你所需要做的就是更改“发布”日期,让它认为这篇文章是在一月份发布的。然后,它将把它归为1月份,而不添加第二个标签。同样,这个方法不使用类别,而是使用发布日期。嗨,安德烈斯,谢谢你的回复。我想要这样的东西在顶部显示季度月份,然后在这个月内显示帖子Hey Atiff,我补充了你的“时间线”类别,我会用它来设置一月到三月的标题。所以现在,当你在你想要的组中标记帖子时,它使用了与显示/隐藏“季度标题”部分非常相似的逻辑。希望这是有道理的。