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
-
Have you looked at the 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,
-drmikeI 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/ please?Thanks
up
Try to get ideas from here:
http://wordpress.org/support/topic/38046?replies=53Hi 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
If that link didn’t help (btw, it gives you the exact code!) then nothing can help you.
Good luck!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
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.
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.php2EDIT: misread your post. Gimme a minute.
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…
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 »'); ?></div>
<p class="info">Posted in <?php the_category(', ') ?> <strong>|</strong> <?php edit_post_link('Edit','','<strong>|</strong>'); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></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 »'); ?></div>
<p class="info">Posted in <?php the_category(', ') ?> <strong>|</strong> <?php edit_post_link('Edit','','<strong>|</strong>'); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></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=1orcategory=2in the above code and change the ID.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/“Ilreca.it Γ¨ in costruzione
Il sito sarΓ presto online”…
check now please
The topic ‘topics from categories’ is closed to new replies.