Saturday 25 May 2013

How do I automate multiple category loops?

How do I automate multiple category loops?

I've asked this question already on the WordPress forum, but it sank like a stone, which isn't at all unusual.
I've set up a general Articles page with multiple loops, in order to display the first three articles from any category within the custom post type "Articles." These are all hard-coded into the template, like the one below, changing only the category ID number:
<?php
  $args = array(
  'cat' => 13,
  'posts_per_page' => 3,
  'post_type' => Article
  );
  query_posts( $args );

  if( have_posts() ):?>
..and so on. What follows is all the necessary code to produce the title, the permalink, the excerpt, etc.
The loops work fine. The problem is that they're hard-coded into the template, which would require that with every new category added, I add a loop to the template file. I need to find a solution so that instead, every time a new category is created it automatically gets added as a block to the Articles page. Also, I need to have it create a link, just as though I were using wp_get_archives, so that each category block links to its own page which contains ALL of the posts within that category (with pagination, if necessary).
I can't think of any function which accomplishes this. Has anyone ever come across this problem before? Or does this require some heavy custom PHP coding that WordPress doesn't support unless hacked?

No comments:

Post a Comment