WordPress.org

Ready to get started?Download WordPress

Forums

last post permalink (3 posts)

  1. maniekxxx
    Member
    Posted 3 years ago #

    Hey
    How can I generate last post permalink?
    I have the link to last past "Latest" in my menu. This is its underlying code:

    <li><a href="<?php bloginfo('url');?>"><?php _e('Latest'); ?></a></li>

    This only works when My front page is set to display last post.
    I want to display static page as front page and keep the "Latest" link functional. How can I generate the last post permalink?

  2. vtxyzzy
    Member
    Posted 3 years ago #

    This is UNTESTED, but should work:

    <?php
    global $post;
    $args = array( 'numberposts' => 1 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post); ?>
    	<li><a href="<?php the_permalink(); ?>"><?php _e('Latest'); ?></a></li>
    <?php endforeach; ?>
  3. maniekxxx
    Member
    Posted 3 years ago #

    Works perfect! Thanks man

Topic Closed

This topic has been closed to new replies.

About this Topic