• 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)
  • 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,
    -drmike

    Thread Starter ugua

    (@ugua)

    I wanna show the latest article for each category (5)
    Can u tell me the exact code and what to replace in my site: https://213.92.85.196/~ilrecai/ please?

    Thanks

    Thread Starter ugua

    (@ugua)

    up

    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

    If that link didn’t help (btw, it gives you the exact code!) then nothing can help you.
    Good luck!

    Thread Starter ugua

    (@ugua)

    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.

    Thread Starter ugua

    (@ugua)

    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:
    https://www.ilreca.it/index.php2

    EDIT: misread your post. Gimme a minute.

    Thread Starter ugua

    (@ugua)

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

    (@ugua)

    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 https://www.ilreca.it/

    “Ilreca.it è in costruzione
    Il sito sarà presto online”

    Thread Starter ugua

    (@ugua)

    check now please

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘topics from categories’ is closed to new replies.