Hey everyone on Stackexchange!
I'm trying to find a way to prioritize posts based on a category in a loop, which is sorted by dates. All posts are grouped under their respective dates. The date labels appear once on top of posts of the same date like this:
Date
- Post1
- Post2
- Post3
Date before that
- Post 4
- Post 5
etc
I'm trying to achieve a result, where if a post belongs to a certain predetermined category (I would only be using 1 category), it would be moved above others under a date as such:
Date
- Post3 (special category)
- Post1
- Post2
Date before that
- etc
I've done research for a while on this topic and I can't figure out whether this would even be possible or not. Some query functions seem to serve a similar purpose, but I'm not certain and the date sorting makes it harder to figure out. Would I need multiple loops or something of that nature?
My loop: http://pastebin.com/Pp0rA5j7
The loop and the sorting mechanism look like this in general (pastebin for a full code):
<?php $w_h = $w_d = $last = 0; ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
if ( date('Yz') == get_the_time('Yz') ) {
if (!$w_d++) echo '<h6>Today</h6>';
} elseif ( date('Yz')-1 == get_the_time('Yz') ) {
if (!$w_h++) echo '<h6>Yesterday</h6>';
} else {
echo the_date('', '<h3>', '</h3>');
}; ?>
// post content
<?php endwhile; ?>
<?php endif; ?>
<?php else : ?>
Sample site: http://goldenred.web44.net (I would like to move the post test 6 with the category "test" above others under February 3, 2013)
I would be extremely thankful if anyone more experienced could help or at least point me towards a general direction. All comments are welcome.