Title: topics from categories
Last modified: August 18, 2016

---

# topics from categories

 *  [ugua](https://wordpress.org/support/users/ugua/)
 * (@ugua)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/)
 * hi guys,
 * on my index.php i would like to show the latest 5 articles. Ok that’s easy enough
   🙂
 * But the articles have to be selected from my 5 categories so that I have 1 article(
   the latest) for each category.
 * How to do that?
 * Thanks

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/topics-from-categories/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/topics-from-categories/page/2/?output_format=md)

 *  [drmike](https://wordpress.org/support/users/drmike/)
 * (@drmike)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513717)
 * Have you looked at the [get_posts](http://codex.wordpress.org/Template_Tags/get_posts)
   function?
 * You may want to spend some time in teh codex. All of the functions used with 
   WP have pages over there with instructions and examples.
 * Hope this helps,
    -drmike
 *  Thread Starter [ugua](https://wordpress.org/support/users/ugua/)
 * (@ugua)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513736)
 * I wanna show the latest article for each category (5)
    Can u tell me the exact
   code and what to replace in my site: [http://213.92.85.196/~ilrecai/](http://213.92.85.196/~ilrecai/)
   please?
 * Thanks
 *  Thread Starter [ugua](https://wordpress.org/support/users/ugua/)
 * (@ugua)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513803)
 * up
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513804)
 * Try to get ideas from here:
    [http://wordpress.org/support/topic/38046?replies=53](http://wordpress.org/support/topic/38046?replies=53)
 *  [ugua2](https://wordpress.org/support/users/ugua2/)
 * (@ugua2)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513837)
 * Hi sorry i register again but i forgot the psw e the email I registered with…
 * anyway i need to know exactly what CODE to put in my site and what to replace.
   I am a beginner and that link didnt help unfortunately
 * Sorry again for double registering
 * Thanks for your time guys
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513842)
 * If that link didn’t help (btw, it gives you the exact code!) then nothing can
   help you.
    Good luck!
 *  Thread Starter [ugua](https://wordpress.org/support/users/ugua/)
 * (@ugua)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513854)
 * all i see in that link is a page with a long code…
    i dont think i need it all
   so can some1 please tell me what code to use and what to replace?
 * ty
 *  [joyced](https://wordpress.org/support/users/joyced/)
 * (@joyced)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513903)
 * I use the following code:
 * `<?php
    $myposts = get_posts('numberposts=1&category=1'); foreach($myposts as
   $post) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
   </li> <?php endforeach; ?>
 * If you repeat that for each category (changing the category ID, of course), you’ll
   get a list with the latest post from each category.
 *  Thread Starter [ugua](https://wordpress.org/support/users/ugua/)
 * (@ugua)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513920)
 * JoyceD or anyone elese would u please tell me what EXACTLY I need to replace 
   in my index.php? I tried but I messed up my code, because I dont know where to
   put my hands.
 * Basically I want to show on my index only the post (title plus article text) 
   of my categories 1 and 2.
 * Please post exactly my index.php
 * Here is the current one:
    [http://www.ilreca.it/index.php2](http://www.ilreca.it/index.php2)
 *  [joyced](https://wordpress.org/support/users/joyced/)
 * (@joyced)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513922)
 * EDIT: misread your post. Gimme a minute.
 *  Thread Starter [ugua](https://wordpress.org/support/users/ugua/)
 * (@ugua)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513923)
 * JoyceD I want it go go on the index.pho so that I have:
 * title, date and the FULL article….can u tell me what code to use please? and 
   what code to replace…
 *  [joyced](https://wordpress.org/support/users/joyced/)
 * (@joyced)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513924)
 * Look for the section that starts with `<?php if (have_posts()) : ?>` and ends
   with `<?php endif; ?>`. Replace that entire section with the following:
 * `<?php
    $lastposts = get_posts('numberposts=1&category=1'); foreach($lastposts
   as $post) : setup_postdata($post); ?> <div class="post" id="post-<?php the_ID();?
   >"> <h1><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php
   the_title(); ?></a> <p class="meta"><?php the_time('F jS, Y') ?> by <?php the_author()?
   ></p> <div class="entry"><?php the_content('Read the rest of this entry &raquo;');?
   ></div> <p class="info">Posted in <?php the_category(', ') ?> <strong>|</strong
   > <?php edit_post_link('Edit','','<strong>|</strong>'); ?> <?php comments_popup_link('
   No Comments &raquo;', '1 Comment &raquo;', '% Comments &raquo;'); ?></p> </div
   > <?php endforeach; ?> <?php $lastposts = get_posts('numberposts=1&category=2');
   foreach($lastposts as $post) : setup_postdata($post); ?> <div class="post" id
   ="post-<?php the_ID(); ?>"> <h1><a href="<?php the_permalink(); ?>" id="post-
   <?php the_ID(); ?>"><?php the_title(); ?></a> <p class="meta"><?php the_time('
   F jS, Y') ?> by <?php the_author() ?></p> <div class="entry"><?php the_content('
   Read the rest of this entry &raquo;'); ?></div> <p class="info">Posted in <?php
   the_category(', ') ?> <strong>|</strong> <?php edit_post_link('Edit','','<strong
   >|</strong>'); ?> <?php comments_popup_link('No Comments &raquo;', '1 Comment&
   raquo;', '% Comments &raquo;'); ?></p> </div> <?php endforeach; ?>
 * Check on your Manage > Categories page that the ID of the categories is correct.
   You said 1 and 2, so I put 1 and 2. If the ID is actually something else, look
   for `category=1` or `category=2` in the above code and change the ID.
 *  Thread Starter [ugua](https://wordpress.org/support/users/ugua/)
 * (@ugua)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513925)
 * seems to work… the only problem is when u click on
    Read the rest of this entry»
   it opens the article in a page where the article is not the only one…check it
   pleas [http://www.ilreca.it/](http://www.ilreca.it/)
 *  [joyced](https://wordpress.org/support/users/joyced/)
 * (@joyced)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513926)
 * “Ilreca.it è in costruzione
    Il sito sarà presto online”
 * …
 *  Thread Starter [ugua](https://wordpress.org/support/users/ugua/)
 * (@ugua)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/#post-513927)
 * check now please

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/topics-from-categories/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/topics-from-categories/page/2/?output_format=md)

The topic ‘topics from categories’ is closed to new replies.

 * 16 replies
 * 5 participants
 * Last reply from: [joyced](https://wordpress.org/support/users/joyced/)
 * Last activity: [19 years, 3 months ago](https://wordpress.org/support/topic/topics-from-categories/page/2/#post-513929)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
