Support » Plugins » a plugin that lets WP display 1 post from each cat in index

  • Hey

    I want the index of my WP to display not a static page, nor posts from specific category, but want the index to display the latest post from the categories that I select. I really wish there is something like that !


Viewing 10 replies - 1 through 10 (of 10 total)
  • I haven’t tried this but it sounds like what you are looking for

    First, thank you very much indeed for help.

    That plugin is nice,but its not what am looking for. That plugin only LISTS the names of the latest POST (not posts) from the wanted category. Yet it shows that in a row text, with the ability to display the post’s excerpt. Plus, you have to make it in a separate page. I dont want that. I want the index itself to display the latest posts of each cats, but with the full text (unless I add the “read more”), and with the same style of the index that I modified. Theplugin merely “lists” the titles of the latest post, not include it in its full shape.

    but thank U again 🙂

    Btw, ive read those topics too, but sadly of no help for my case:


    I wrote up some code for you. It works be making multiple passes through the loop (once for each category), displaying the latest post from each.


    Open your themes index.php file

    Find this line:

    <?php if (have_posts()) : ?>

    Before it, add this:

    $cats = array(1, 2, 3);
    foreach ($cats as $c) {
    query_posts('showposts=1&cat=' . $c);

    (where 1, 2, and 3 are the categories you want to display a post from

    Find this line:

    <?php endif; ?>

    After it, add this:

    <?php } ?>

    Try it out and see if it works for you. It should be a good starting point at least.

    Hey Dagon Design. Thank you so much for caring.

    I have done exactly what you said (including the cats number I want).

    Yet I get this :

    Parse error: syntax error, unexpected T_VARIABLE in /-------/blog/wp-content/themes/movie-theme/index.php on line 30

    Line 30 of that file is completely blank !

    btw, there were two <?php endif; ?> I added <?php } ?> after the endif tag that comes at the end, and not the one that comes after the tags command:
    <?php if ( function_exists('the_tags') ) : ?><?php the_tags(); ?> <?php endif; ?>

    I even ommitted that endif after the tags command, but the same error

    ( is it normal to have endif in two places, like this case, and , do blank lines matter in php files (not blank at the beginning of a line, but blank lines that are produces when copying/pasting from place to place) ).


    STVWLF (Really BIG thanx to him) has sent me a solution (after I emailed him), suggesting the following similar solution, yet it sadly brought to the same error message.
    And I think it needs to be re-shaped because I use other custom codes between the <?php while (have_posts()) : the_post(); ?> and the <?php the_content like the post views, the ratings, the tags, the edit link, etc.

    If it is the same list of categories every time, in the same display order, you could do something like this

    $display_cats =  array(1, 6, 13, 24, 9, 7);
              // this is the list of category id's in the order you want them displayed
    foreach ($display_cats as $cat) {
       $posts = new WP_Query("cat=$cat&showposts=1");
       while($posts->have_posts()) : $posts->the_post();?>
            <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
            <?php the_content(__('Read the story &raquo;'));?></div>
       <?php endwhile; ?>
    <?php } ?>

    I haven’t tested that code – it probably has some mistakes in it. I am showing an approach to solving the problem.

    What the code does: create an array of all the category codes you want to display in the order you want them displayed. Loop through that category array creating a WordPress loop for each category. Display the most recent post in the category that is being processed. Loop to the next category in the category array list.

    take care



    UP (desperately)

    The first section of code worked wonderfully for me. Thank you Dagon Design! I even used another loop to create it so I had one category pulling one entry and another category pulling that latest three entries.


Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘a plugin that lets WP display 1 post from each cat in index’ is closed to new replies.