• Please bear with me…I barely even know how to describe this.

    I’m trying to create a page which shows a list of posts of the custom post type “Articles.” Each category for this post type shows the latest 3 articles, with a link to a page for that category which would show all of them. Right now, I have this hard-coded into the template by repeating this for each category, altering only the numerical ID:

    <?php
          $args = array(
          'cat' => 13,
          'posts_per_page' => 3,
          'post_type' => Article
          );
          query_posts( $args );
    
          if( have_posts() ):?>

    There follows all the necessary code to produce the title, the permalink, the excerpt, etc. Then, a “More” link, which right now is simply a placeholder which doesn’t go anywhere at all.

    This works just fine (except for the “More” link); but as categories are added, I would have to hard-code each one into the template in order to make it work. What I want is to automate this. My limited understanding of PHP informs me this is not what wp_get_archives was meant to do. What I need to do, in plain language, would be the PHP equivalent of this:

    “Go to the database. Look up all the Articles. For every category you find, get the 3 most recent, and print them out in their own div using the title and excerpt of each, then create a link to a page which will display all of them, excluding all other categories, 20 to a page, with pagination.”

    If anyone can even point out which function might handle this, I’d be grateful.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘How to automate multiple category loops?’ is closed to new replies.