WordPress.org

Ready to get started?Download WordPress

Forums

Display 5 Recent Entries (20 posts)

  1. Katrina
    Member
    Posted 9 years ago #

    I searched and found nothing useful, so here goes: How do I plug the last 5 posts I made into my sidebar?

  2. Mark (podz)
    Support Maven
    Posted 9 years ago #

    Use a plugin :)
    http://mtdewvirus.com/code/wordpress-plugins/

    I believe there is a native wp function somewhere, but Nick's code works perfectly too.

  3. Katrina
    Member
    Posted 9 years ago #

    Thanks, podz, but I've got it. For everyone else who needs it it's this:

    blockquote

  4. 5 Newest Posts:
      <?php $latest = new WP_Query('showposts=5');
      while ($latest->have_posts()) : $latest->the_post(); ?>
      <?php
      $title = get_the_title();
      if (strlen($title) >= 35)
      $title = substr($title, 0, 35) . '…';
      ?>

    • "><?php echo $title; ?>
    • <?php endwhile; ?>

  5. blockquote

  • Katrina
    Member
    Posted 9 years ago #

    scap that, it seems to be wrong:

  • 5 Newest Posts:
      <?php $latest = new WP_Query('showposts=5');
      while ($latest->have_posts()) : $latest->the_post(); ?>
      <?php
      $title = get_the_title();
      if (strlen($title) >= 35)
      $title = substr($title, 0, 35) . '…';
      ?>

    • "><?php echo $title; ?>
    • <?php endwhile; ?>

  • Katrina
    Member
    Posted 9 years ago #

    darn it, just get it here: http://randomfire.fierymill.net

  • Minna
    Member
    Posted 9 years ago #

    It's also pretty easy to use wp_get_archives with type parametre set to 'postbypost' and limit to 5 (or so). There is even an example of this use on the template tag page (in Codex).

    Of course, that doesn't limit the title length.

  • whooami
    Member
    Posted 9 years ago #

    err, ok, the easy way is like this though :)

    <?php get_archives('postbypost', 5, 'html', '', '', false) ?>

    its a holdover from 1.2.* that seems to be working on my 1.5 blog

    edit: yeah, what minna said! :)

  • fro
    Member
    Posted 8 years ago #

    OK, Is there a way to add the latest entries to only the stories when you click read more? As you see in mine, the latest entries are showing on the index on every post.

  • dgstinner
    Member
    Posted 8 years ago #

    I use a hack you can find here

  • fro
    Member
    Posted 8 years ago #

    does that work with 1.5?

  • moshu
    Member
    Posted 8 years ago #

    fro, you got already the code, so you don't really need that hack... you just inserted the code in the wrong place.

  • fro
    Member
    Posted 8 years ago #

    where do i insert it at?

    i tried a ton of places

  • Lorelle
    Member
    Posted 8 years ago #

    In the my-hacks.php that you probably don't have and have to create with the hack in it. And then upload it to, if memory serves, the root directory you have WordPress installed to. Oh, and you have to go to one of the Options panels and activate it...I can't remember where off the top of my head, but it is called the my-hacks legacy....

    But this is a LOT of work. Do you have something against plugins?

    Customizable Post Listings plugin makes this SO EASY. Just activate it and put the following in your sidebar:

    <li id="recent"><?php _e('Recent Articles'); ?><ul>
    <?php c2c_get_recent_posts(5); ?></ul></li>

    or customize the title or whatever to fit your own sidebar.

    And check out http://codex.wordpress.org/Customizing_Your_Sidebar

  • fro
    Member
    Posted 8 years ago #

    ok - but replying to moshu - where do i put the code?

  • moshu
    Member
    Posted 8 years ago #

    where do you want the 5 to appear?

  • fro
    Member
    Posted 8 years ago #

    When I click the permalink - I want it only to show up right under the body and just above the comments - no where on the main page should it show up

  • moshu
    Member
    Posted 8 years ago #

    Do you have a single.php template in your theme? If yes, put the code into that template file.
    I the answer is no, then you'll have to use some if statement in the index.php file to display it only when a single post is viewed. See the conditional template tags in the Codex.

  • fro
    Member
    Posted 8 years ago #

    well i can't figure that out - i'm not to much into programing - possibly a little help from someone?

  • fro
    Member
    Posted 8 years ago #

    Nevermind - I did have a single.php - sorry about that - it now works! Check it out! http://www.frosblog.com

    Now is there a way to put the recent entries at the very bottom of the blog... lets say I only have a couple of post on the main page, and want to list, lets say, 5 entries below that, is it possible to put those five only on the main page at the bottom?

  • moshu
    Member
    Posted 8 years ago #

    You probably can. Put it AFTER the loop, just before the "next-previous" code.

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags

    No tags yet.