Divide Loop Into Days & Categories

If you could help, I’d greatly appreciate it, because I’m halfway there, but I’m currently stuck!

The site I’m working on needs to have it’s posts, within the loop, divided up by days, and then under those days, be divided up by categories.

Currently, I have the days working, but can’t for the life of me get the categories divided under the days. Here’s what I basically have at the moment as far as layout goes:

<h2>Wednesday, July 30, 2014</h2>
<POST ONE>
<POST TWO>
<POST THREE>
<h2>Tuesday, July 29, 2014</h2>
<POST ONE>
<POST TWO>

It’s great that it’s working and the days are divided, but like I said, I need those days to be divided into categories as well. For example, I need something like this:

<h2>Wednesday, July 30, 2014</h2>
<h3>Columns</h3>
<POST ONE>
<h3>Links</h3>
<POST TWO>
<POST THREE>
<h2>Tuesday, July 29, 2014</h2>
<h3>Columns</h3>
<POST ONE>
<h3>Links</h3>
<POST TWO>

Currently, this is what my loop looks like:

<div class="blog-style">
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                <?php if( $current_date != get_the_date('l, F j, Y') ){
                    echo '<h2 class="date-separator">'.get_the_date('l, F j, Y').'</h2>';
                    $current_date = get_the_date('l, F j, Y');
                } ?>
                <?php get_template_part(THEME_LOOP."post"); ?>
            <?php $counter++; ?>
            <?php endwhile; else: ?>
                <?php get_template_part(THEME_LOOP."no","post"); ?>
            <?php endif; ?>
            <?php customized_nav_btns($paged, $wp_query->max_num_pages); ?>
        </div>

Once again, like I said, any help would be greatly appreciated! Thanks for taking a look!

UPDATE: I’ve been messing around and I think I’m almost there. This should be working, but I can’t get any posts to spit out. Would someone mind taking a look and let me know what’s going wrong? Thanks!

Here’s my current loop now:

<div class="blog-style">
            <?php
            $_start=(floor($wp_query->query_vars['paged'])-1)*5;
            if($_start<0){$_start=0;}

            for($_d=$_start;$_d<$_start+5;$_d++) {
                $_today=date("l, F j, Y", mktime(0, 0, 0, date("m")  , date("d")-$_d, date("Y")));
                echo "<h2 class=\"date-separator\">$_today</h2>\n";
            ?>
          <div class="sectionbox">
            <div class="sectionhead">Columns</div>
                <div class="clear"></div>
                    <div class="sectioncontent">
                      <div class="links">
                       <?
                          $_year=date("Y", mktime(0, 0, 0, date("m")  , date("d")-$_d, date("Y")));
                          $_mon=date("m", mktime(0, 0, 0, date("m")  , date("d")-$_d, date("Y")));
                          $_day=date("d", mktime(0, 0, 0, date("m")  , date("d")-$_d, date("Y")));
                          $the_query = new WP_Query( 'year=" . $_year . "&monthnum=' . $_mon . '&day=' . $_day.'&category_name=Column-2' );
                          while ( $the_query->have_posts() ) : $the_query->the_post();
                            global $wpdb;
                            $comments = $wpdb->get_results("SELECT DISTINCT(comment_content) FROM $wpdb->comments WHERE comment_post_ID ='".get_the_ID()."' AND comment_approved = '1'");
                            $_count = count($comments);
                            $_comment="";
                            if($_count==1)
                              {
                              $_comment=" (1 comment)";
                              }
                            elseif($_count>1)
                              {
                              $_comment=" ($_count comments)";
                              }
                            $excerpt=str_replace("\n",' ',get_the_excerpt());
                            echo "<a href=\""https://wordpress.stackexchange.com/questions/156453/.get_permalink()."\" title=\"$excerpt\"><b>".get_the_title()."</b>
                                  <img src=\"".get_bloginfo('template_url')."/images/comment.jpg\" width=\"22\" height=\"22\" align=\"absmiddle\" alt=\"\" />
                                  <!--$_count--><fb:comments-count href="https://wordpress.stackexchange.com/questions/156453/.get_permalink()."></fb:comments-count></a> &mdash; ".get_the_author()."<br>\n";                  endwhile;
                          wp_reset_postdata();
                        ?>
                        <?php
                        if(function_exists('show_columns')) 
                          {
                          show_columns(30,$_d);
                          }
                        ?>
                      </div>
                  <div class="clear"></div>
                </div>
            <div class="clear"></div>
          </div>        
          <div class="clear"></div>

          <div class="sectionbox">
            <div class="sectionhead">News</div>
                <div class="clear"></div>
                    <div class="sectioncontent">
                      <?php 
                          $_year=date("Y", mktime(0, 0, 0, date("m")  , date("d")-$_d, date("Y")));
                          $_mon=date("m", mktime(0, 0, 0, date("m")  , date("d")-$_d, date("Y")));
                          $_day=date("d", mktime(0, 0, 0, date("m")  , date("d")-$_d, date("Y")));
                          $the_query = new WP_Query( 'year=" . $_year . "&monthnum=' . $_mon . '&day=' . $_day.'&cat=-3,-2204' );
                          while ( $the_query->have_posts() ) : $the_query->the_post();
                            global $wpdb;
                            $comments = $wpdb->get_results("SELECT DISTINCT(comment_content) FROM $wpdb->comments WHERE comment_post_ID ='".get_the_ID()."' AND comment_approved = '1'");
                            $_count = count($comments);
                            $_comment="";
                            if($_count==1)
                              {
                              $_comment=" (1 comment)";
                              }
                            elseif($_count>1)
                              {
                              $_comment=" ($_count comments)";
                              }
                            $excerpt=str_replace("\n",' ',get_the_excerpt());
                            echo "<a href=\""https://wordpress.stackexchange.com/questions/156453/.get_permalink()."\" title=\"$excerpt\"><b>".get_the_title()."</b>
                                  <img src=\"".get_bloginfo('template_url')."/images/comment.jpg\" width=\"22\" height=\"22\" align=\"absmiddle\" alt=\"\" />
                                  <!-- $_count --><fb:comments-count href="https://wordpress.stackexchange.com/questions/156453/.get_permalink()."></fb:comments-count></a> &mdash; ".get_the_author()."<br>\n";                  
                                  endwhile;
                          wp_reset_postdata();
                       ?>
                      <div class="news">
                        <?php
                            if(function_exists('show_daily_links')) 
                            {
                            show_daily_links(30,$_d,1);
                            }
                          ?>
                      </div>
                  <div class="clear"></div>
            </div>
            <div class="clear"></div>
          </div>



<?
    if($_d==$_start)
#     if(false)
      {
?>

<?
      }
?>


<?
    }
?>



<div class="navigation" style="width:100%;">
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } 
else { ?>
    <div class="right"><?php next_posts_link('Next Page &raquo;') ?></div>
    <div class="left" style="float:left"><?php previous_posts_link('&laquo; Previous Page') ?></div>
<?php } ?>
</div>
        </div>

0

Leave a Comment