Forums

Dividing post by Date and seperator (2 posts)

  1. ranbirchd
    Member
    Posted 1 year ago #

    Hi All:

    I have a site http://designingway.com/fun_deals in this what I want that post should appear by date, for example right now on front page, there are some deals from today, and one from last week, if they were seperated by a divider with the date somehow that would be awesome.

    Kindly see the example what I am looking
    http://www.creativedesignperth.com/example.jpg

    Thanks
    Ranbir

  2. vtxyzzy
    Member
    Posted 1 year ago #

    You will need to alter the template being used. Below is some sample code that you can adapt to your theme:

    $in_date = '';
    query_posts('ignore_sticky_posts=1&posts_per_page=22');
    if (have_posts()) {
       while (have_posts()) {
          the_post();
          $this_date = get_the_time('Y-m-d');
          if ($in_date && $in_date != $this_date) {
             echo "<p> $this_date ======================</p>";
          }
          $in_date = $this_date;
          // rest of the loop

    Basically you need to keep track of the date that is currently being shown ($in_date) and test it against each post date ($this_date). If they are not equal, then echo your divider. Then set $in_date to $this_date.

Topic Closed

This topic has been closed to new replies.

About this Topic