Forums

Show Last Post With Permalink To Previous Entry (8 posts)

  1. LeoMoon
    Member
    Posted 2 years ago #

    Hi, I've been trying to do this for a while now and I searched everywhere but I couldn't make it work.

    I want to show the last post with permalink to previous entry inside a Page.

    I tried and I got it to showing the last entry only but I had to use PHP Shortcode plugin to execute php inside a page so here is the code sofar:
    [php]
    get_header();
    query_posts('posts_per_page=1');
    [/php]

    Any help would be greatly appreciated.

  2. Pierreb
    Member
    Posted 2 years ago #

    Perhaps this is what you looking for?
    http://scribu.net/wordpress/smarter-navigation
    Adds page navigation to let users navigate between posts.

  3. LeoMoon
    Member
    Posted 2 years ago #

    Tnx for your reply. :)

    That might work on an index. On a page it won't show anything.

    I want to show the last post with permalink to previous entry inside a page.

    Nobody else knows?

    Tnx.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    You could create a custom page template and incorporate get_posts().

  5. LeoMoon
    Member
    Posted 2 years ago #

    I wrote what I exactly wanted:
    <?php
    get_header();
    query_posts('posts_per_page=1');
    ?>
    <?php
    global $post;
    $myposts = get_posts('numberposts=1&offset=1&category=-3');
    foreach($myposts as $post) :
    setup_postdata($post);
    ?>
    "><?php the_title(); ?>
    <?php endforeach; ?>

    But the problem is even I wrote to show the last post first, it shows the previous link first! You would think WordPress will executes lines top to bottom.

  6. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    If your code snippet isn't inside backticks, it's not readable...

  7. LeoMoon
    Member
    Posted 2 years ago #

    I gave up. I pasted the code below into the top navigation menu. So it will show the premalink to the last blog post entry!
    <?php
    global $post;
    $myposts = get_posts('numberposts=1&category=-3');
    foreach($myposts as $post) :
    setup_postdata($post);
    ?>

  8. ">Blog
  9. <?php endforeach; ?>

  • irengba
    Member
    Posted 2 years ago #

    Not sure if this will help.
    Check out this link http://codex.wordpress.org/Template_Tags/get_posts

    The code has to be inside the wordpress loop.

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags