• Resolved dfwgreg

    (@dfwgreg)


    Hi everyone,
    I’m having problems adding a div to a group of posts that are written on a particular date. This is the code I’m using:

    <?php $args = array( 'post_type'=>'wlinks' ); query_posts( $args ); ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	<?php the_date('','<div><h2>','</h2>'); ?>
    	<?php the_title(); ?><br /></div>
    
    <?php endwhile; ?>
    <?php else : ?>
    <?php endif; ?>

    Website where the problem occurs: https://alttv.net/files/linkroll.php

    It’s fine if I have only one post but the problem is if there are more than one post, the first post is in the div and the rest are outside the div. I would like to group all post by date in a div.

    Here’s a graphical example of the problem:
    <div>
    <title>
    <post>
    </div>
    <post>
    <post>

    What I’m trying to accomplish:
    <div>
    <title>
    <post>
    <post>
    <post>
    </div>

    Thanks for the help,
    Gregory S.

Viewing 1 replies (of 1 total)
  • Thread Starter dfwgreg

    (@dfwgreg)

    Nevermind, I found a solution.

    <?php $args = array( 'post_type'=>'wlinks' ); query_posts( $args ); ?>
    
    <?php
    $day_check = '';
    while (have_posts()) : the_post();
      $day = get_the_date('d');
      if ($day != $day_check) {
        if ($day_check != '') {
          echo '</div>'; // close the list here
        }
        echo '<div>', get_the_date()  ;
      }
    ?>
    <li><?php the_title(); ?></a></li>
    <?php
    $day_check = $day;
    endwhile; ?>

    Sorry for clogging the forum,
    Gregory S.

Viewing 1 replies (of 1 total)
  • The topic ‘Add div to group posts by date?’ is closed to new replies.