List one latest post per category on frontpage view

von Joern am 3. Mrz. 2009 | Keine Kommentare

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; ?> &raquo;</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 (file removed..)

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.

one post per category wordpress


Du findest mich auch auf Twitter und Facebook!

Schreibe einen Kommentar

Pflichtfelder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.