• Resolved dinneenp

    (@dinneenp)


    Hi,
    I’m using Monotone theme, site is 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.
    Thanks,
    Patrick.

Viewing 1 replies (of 1 total)
  • You’d have to fetch that post, then produce a menu item for it..

    <?php
    $latest_post = get_posts( array( 'posts_per_page' => '1', 'paged' => 1, 'orderby' => 'date', 'order' => 'desc', 'post_type' => 'post', 'post_status' => 'publish' ) );
    
    $latest_post = $latest_post[0];
    
    $latest_link = '<a href="' . get_permalink( $latest_post->ID ) . '" title=" . the_title_attribute( array( 'echo' => 0 ) ) . ">Recent</a>';
    // wp_reset_query(); // Uncomment this line if the code appears to cause problems with other queries
    ?>
    <!-- example menu element follows -->
    <li class=""<?php echo ( is_single( $latest_post->ID ) ) ? 'active_class' : 'non_active'; ?>>><?php echo $latest_link; ?></li>

    Included active/non-active classes, update those names as appropriate..

    Hope that helps..

Viewing 1 replies (of 1 total)
  • The topic ‘create link to 'most recent post'?’ is closed to new replies.