Wordpress help - display last 10 posts titles

Discussion in 'WordPress' started by Scorpiono, Oct 3, 2007.

  1. #1
    Hello,

    Does anyone know the smallest piece of code to add to display the last 10 post titles from the category I'm in atm?

    Also, have the <a> tag on them, that will go to the permalink (basic linking)

    Thank you - will add rep
    - Scorpiono
     
    Scorpiono, Oct 3, 2007 IP
  2. arwen54

    arwen54 Active Member

    Messages:
    632
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    60
    #2
    hi there

    First you must have the plugin called exec-php installed and activated so that you can insert php code into your posts

    next:
    try inserting this snippet of code in your post:
    <p>< ?php wp_get_archives('type=postbypost&limit=10&format=custom&cat_ID=?'); ?></p>
    Code (markup):
    you see where cat_ID=?
    replace the question mark with your category number..you can find that by going to Manage/Categories and place your cursor on the edit link next to the category and you will see the id number on your browser's taskbar

    let me know if this works :)
     
    arwen54, Oct 3, 2007 IP
  3. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #3
    I'm thinking of putting this on the sidebar, and it will grab the current category by itself, anyway?
     
    Scorpiono, Oct 3, 2007 IP
  4. arwen54

    arwen54 Active Member

    Messages:
    632
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    60
    #4
    no, it won't...

    not without a plugin or some coding
     
    arwen54, Oct 3, 2007 IP
  5. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #5
    Answer:

    <h2>Latest posts:</h2>
    <?php while (have_posts()) : the_post();?>
    <?php $postCount++;?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>" style="border-bottom:1px dotted #ddd;line-height:2em;">&raquo; <?php the_title(); ?></a><br />
    <?php endwhile; ?>
     
    Scorpiono, Oct 5, 2007 IP
  6. just-4-teens

    just-4-teens Peon

    Messages:
    3,967
    Likes Received:
    168
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This currently works for me

    
    <h2>Last Posts</h2>
    <ul>
    <?php
    $posts = get_posts('numberposts=10&offset=0');
    foreach ($posts as $post) :
    ?>
    <li><a href="<?php the_permalink(); ?>" title="<?php the_title() ?>"><?php the_title() ?></a></li>
    <?php
    endforeach;
    ?>
    </ul>
    
    PHP:
    this will display the last 10 post made,
    change numberposts=10 to how ever many last post u want displayed. (e.g. numberposts=20 will show 20 post)
    change &offset=0 to show only post after this value (e.g. &offset=1 would show all last post execpt the most recently posted)
     
    just-4-teens, Oct 6, 2007 IP
  7. Lastbutnotleast

    Lastbutnotleast Peon

    Messages:
    2,612
    Likes Received:
    105
    Best Answers:
    0
    Trophy Points:
    0
    #7
    And if you use a new theme already displaying the last 10 posts titles or so ?
     
    Lastbutnotleast, Oct 6, 2007 IP