individuelles und professionelles Webdesign, Programmierung und Internetmarketing

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; ?> &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

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:

  1. Category view in Arthemia optimized
    Question: Can you display headline & featured block to each...
  2. List some pages with content in Wordpress
    To list pages in WordPress you normally take this: <?php...
  3. list pages custom styling in arthemia category bar
    Some users of of arthemia theme would like to display...
  4. List subcategories in category bar of arthemia theme
    In the WordPress theme Arthemia theme by Michael Jubel is...
  5. Exclude one headline post from frontpage but not if is paged
    The problem: I got a WordPress site with feature headline,...
3. March 2009 • Kategorie: Wordpress Tips Tags: ,
These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Facebook
  • LinkedIn
  • TwitThis

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.

2 Kommentare »

  1. 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.

  2. 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

Kommentieren

Interessante Links zu one post per category wordpress

New WordPress plug-in that enables custom primary category in permalinks

With this plugin users can define one(primary) category per post that will be used to generate the post permalink. It has an intuitive,Javascript free interface, and needs no further source code modifications to work or brakes permalinks if it gets uninstalled. Now WordPress users can enjoy the same primary category features offered by MT!

Funky Luftbrücke from New Orleans nach Hamburg

...das natürlich nicht, denn per elektronischer Post habe ... Funkadelics “One Nation Under a Groove” und George

WordPress " Support " One post per category in home page

WordPress " Support " How-To and Troubleshooting [resolved] One post per category in home ... I know how to exclude categories in home page and how to set a number of total ...

List one latest post per category on frontpage view – Web ...

I will give you here a code to list only one post per selected category. You could include this into your index.php query for the last posts of categories put