Creating lists of posts to be sorted by date, category, and alphabetically
-
I keep a blog with reviews of all the movies I see. At the end of the year, I like to compile a list of those movies in three different ways (but displayed on a single page): by date (Jan-Dec), by category (each rating level is its own category), and alphabetically. Previously I’ve done this manually but I feel like this should be easy enough to do with WordPress now that I have all my content archived on my website. The trouble is that I haven’t yet found info in the codex or a plugin that will do this for me the way I want.
Essentially it should look like this:
- By Date (sorted oldest to newest) - Jan 10 - Movie #1 - Jan 14 - Movie #2 - Feb 5 - Movie #3 (etc.) - By Category (sorted highest to lowest) - Movie #2 (Category: 5 Stars) - Movie #3 (Category: 2.5 Stars) - Movie #1 (Category: 1 Star) - Alphabetically (sorted A to Z) - A Titles - B Titles - C Titles (etc.)
The difficulties I’m running into are:
1) Because I want this page to be dynamically generated by year using date.php, WordPress will try and place a limit on the number of entries that can appear on a given page unless I manually override this number in the Settings area. I have it set to 100, which is fine, but I don’t know how to override it through The Loop in order to show ALL entries but limit it to all entries from which ever year the date.php page is displaying (be it 2009, 2008, 2007, etc.). Any time I’ve tried to get it to show all the entries, it shows me every last entry on my site, from 2006 to today.
2) There only seems to be a template tag to list the categories themselves as links, not to make a list of all the entries (in a given year) sorted by category. I don’t need this area broken down into subsections by category, a giant list will suffice, I just need to make sure that this content is sorted in descending order by category name overall. I’ve seen a couple of tweaks here and there but they require being used on an is_category template and I need them to be used on a date-based template.
3) The alphabetical area seems to be working fine thus far. The code I’ve used is as follows:
<?php
$posts = query_posts($query_string .
‘&orderby=title&order=asc&posts_per_page=-1’);if (have_posts()) : while (have_posts()) : the_post(); ?>
<li >< a href=”<?php the_permalink() ?>” ><?php the_title(); ?></ a></ li>
<?php endwhile; else: ?><li ><?php _e(‘Sorry, no posts matched your criteria.’); ?></ li>
<?php endif; ?>(My apologies for the weird nbsp; around the list items in the code; they weren’t showing up in this post without them, but obviously they are not included in the actual code on my template.) Not being an expert, I don’t know how proper this code is, but it is at the very least generating this list the way I would like.
I’m not fussed about having three separate loops on the page to display these three types of lists, but if they could be combined into a single loop that would probably be even better. I’m not super skilled with PHP but am trying my best to figure this out.
Thanks in advance!
- The topic ‘Creating lists of posts to be sorted by date, category, and alphabetically’ is closed to new replies.