WordPress.org

Support

Support » How-To and Troubleshooting » last post permalink

last post permalink

  • 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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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; ?>

    Works perfect! Thanks man

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘last post permalink’ is closed to new replies.
Skip to toolbar