Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Wordpress: create link to most recent post?

  • 05-11-2010 12:53PM
    #1
    Registered Users, Registered Users 2 Posts: 8,261 ✭✭✭


    Hi,
    I'm using Monotone theme, site is <a href="http://photoblog.ie">.
    I have a set homepage.
    In my navigation menu (in header) I want to add 'recent', which will link to the most recent post.

    At the moment I have to update the code each time I add a new post so +1 to the archive number-
    <li><a href="<?php bloginfo('url'); ?>/archives/1545/">recent</a></li>

    Thanks,
    Patrick.


Comments

  • Registered Users, Registered Users 2 Posts: 16,415 ✭✭✭✭Trojan


    This should work for you:
    <?php $my_query = new WP_Query('showposts=1'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <li class="page_item"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    

    (Can probably be optimised a bit more to remove while loop).

    HTH.


Advertisement