• Resolved zakphi

    (@zakphi)


    i know with the_date(), it will display the month for a group of posts published on the same day, and will be displayed if a group of posts are published the next day. is there a way to have the_date() display the month only once per month?

    basically, i want something like this:
    May
    5-13-14
    post #1
    post #2
    post #3
    5-12-14
    post#1
    post#2
    post#3

Viewing 5 replies - 1 through 5 (of 5 total)
  • I’m not sure what you’re trying to achieve?

    You want to list all posts based on month day and year?

    What have you tried? What does your loop look like?

    Thread Starter zakphi

    (@zakphi)

    i want to group posts by month, but not have the month display every day.

    here is the code for my blog page

    <div class="entry-content">
              <?php the_content(); ?></div>
              <div class="journals">
                  <?php
                    $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
                    $args = array(
                      'posts_per_page' => 10,
                      'paged' => $paged
                    );
                    $loop = new WP_Query( $args );
                  ?>
                  <ul class="journal-post">
                  <?php while ( $loop->have_posts() ) : $loop->the_post();?>
                      <span class="post-month"><?php $my_date = the_date('F', '<h3>', '</h3>', FALSE); echo $my_date; ?></span>
                      <li>
                        <a href="<?php echo get_permalink(); ?>">
                          <h2><?php the_title();?></h2>
                        </a>
                        <h3><?php echo get_the_date( 'm-d-y'); ?></h3>
                        <span class="content"><?php the_excerpt(); ?></span>
                        <span class="tags"><?php the_tags('',' '); ?></span>
                      </li>
                  <?php endwhile;?>
                  </ul><!-- .journal -->
                  <div class="pagination">
                    <?php
                      $big = 999999999; // need an unlikely integer
                      echo paginate_links( array(
                        'base'       => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                        'format'     => '?paged=%#%',
                        'current'    => max( 1, get_query_var('paged') ),
                        'end_size'   => 0,
                        'mid_size'   => 1,
                        'prev_text'  => 'Previous',
                        'next_text'  => 'Next',
                        'type'       => 'list',
                        'total'      => $loop->max_num_pages
                      ) );
                    ?>
                  </div><!-- .pagination -->
              </div><!-- .journals -->
            <?php endwhile; // end of the loop. ?>

    and here is a screenshot of it
    https://drive.google.com/file/d/0B99cydODex2QT3hxb0VXVGticDA/edit?usp=sharing

    as you can tell, i have posts from different days this week, and the month is displayed each day. i just want the month to be displayed once.

    So maybe remove this line, so it doesn’t print the date with each post?
    <h3><?php echo get_the_date( 'm-d-y'); ?></h3>

    Thread Starter zakphi

    (@zakphi)

    did that. but like you said it removes the date, and i want the date to be displayed. unfortunately, the month is still displayed, each day there are new posts

    Thread Starter zakphi

    (@zakphi)

    just wanted to let you know I figured a way to do this

    <?php $latest = ''; ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post();?>
    <?php $date = get_the_date('F');
     if($date !== $latest)
    {
        $latest = $date;
    ?>
    <h3 class="post-month"><?php echo $date;?></h3>
    <?php } ?>

    it may not be the best way to do it, but it works.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘how to group posts by month’ is closed to new replies.