List one latest post per category on frontpage view
I will give you here a code to list only one post per selected category. You could include this code into your index.php to query for the last posts of the categories you put into this code.
The first and the last line makes the post appear only on first page.
In the array of categories are six numbers now which you have to replace with the category IDs of your categories. It could be more or less, order them as you wish.
<?php if(!is_paged()) { // display only on page one if is not paged ?>
<?php $display_categories = array(8,5,4,6,7,3); foreach ($display_categories as $frontcats) { ?>
<?php $catposts = get_posts("showposts=1&cat=$frontcats"); foreach($catposts as $post) : setup_postdata($post); ?>
<h3 class=cat_title><a href="<?php echo get_category_link($frontcats);?>"><?php $this_category = get_category($frontcats); ?><?php echo $this_category->cat_name; ?> »</a></h3>
<div class="title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></div>
<div class="meta"><?php the_time('j M Y') ?> | <?php comments_popup_link('No Comment', 'One Comment', '% Comments');?></div>
<?php $values = get_post_custom_values("Image");if (isset($values[0])) { ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<img src="<?php echo $values[0]; ?>" alt="<?php the_title(); ?>" /></a>
<?php } //end of image if set in custom field ?>
<?php the_excerpt(); ?>
<?php endforeach; // end of post ?>
<?php } ?>
<?php } // end of FIRST PAGE ?>
Actually I made this query for Arthemia theme, if you want you find the complete modified index.php renamed as arthemia_onepostpercat_index.txt here:
arthemia index.php modified to dispay one post per category on first page
This file is an Arthemia index.php and will show on the first page only one post of each selected category.
Pagination should work and will show you on page two the list of posts as you set them in the theme. Here you are again free to choose any category to exclude as normally done in this theme.
Related posts:
- Category view in Arthemia optimized
Question: Can you display headline & featured block to each... - List some pages with content in Wordpress
To list pages in WordPress you normally take this: <?php... - list pages custom styling in arthemia category bar
Some users of of arthemia theme would like to display... - List subcategories in category bar of arthemia theme
In the WordPress theme Arthemia theme by Michael Jubel is... - Exclude one headline post from frontpage but not if is paged
The problem: I got a WordPress site with feature headline,...
JW ist Freelance Webdeveloper
Website Questions? Please ask in Webdesign Forum
You can follow any responses to this entry through the
RSS 2.0 feed.
You can leave a response, or trackback from your own site.






Hi JW, I use this script but I have a problem. When I select the categories it only shows the title and the name of the category, but the text of the lastest news of every one of the category do not correspond to this category.
Marcos, thanks for the hint, I updated the code and hope it works now.
changes in the index.php for arthemia are in lines: 76, 77 and 79 and one additional line in 92