Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a landing page that, among other things, features an excerpt from the most recent post with a "Continue Reading" link that should take the reader to the most recent post.

In my search, I've found a lot of guides on how to link to the most recent post within a specified category, but not much on the most recent post regardless of category(because it will vary).

ETA:

<li>
                <h2><a href="http://growingedgecoaching.com/blog">Growing Edge Blog</a></h2>
                    <?php
                    // Get the most recent post
                    $the_query = new WP_Query( 'posts_per_page=1' );

                    // Pull the excerpt
                    while ( $the_query->have_posts() ) : $the_query->the_post();
                        the_excerpt();
                    endwhile;

                    // Reset Post Data
                    wp_reset_postdata(); 
                    ?>
                <div class="forward-link">

                    <?php
                    $latest = new WP_Query( array( 'posts_per_page' => 1 ) );
                    while( $latest->have_posts() ) :
                        $latest->the_post();
                        echo '<a href="' . get_permalink() . '>' . get_the_title() . '</a>';
                    endwhile;
                    ?>

                </div><!-- end forward-link -->
            </li>

Any ideas? Thanks.

share|improve this question
    
you want 2nd block to show recent post, 3rd block for tweeter right! what you want in first block ? –  amit Aug 1 '12 at 17:56
    
the first, far left block is the most recent post excerpt that should have the link to the full most recent post. the middle block is the "about" section, and the third, far right block contains the most recent tweets. –  user1255049 Aug 1 '12 at 17:58

2 Answers 2

up vote 2 down vote accepted

This code uses snippet from @Milo to suit your requirement.

Replace the code you've provided in question with this -

<li>
    <h2><a href="http://growingedgecoaching.com/blog">Growing Edge Blog</a></h2>
    <?php
    $latest = new WP_Query( array( 'posts_per_page' => 1 ) );
    while( $latest->have_posts() ) : $latest->the_post();
    ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_excerpt(); ?>
    <div class="forward-link">
        <a href="<?php the_permalink(); ?>">Read More..</a>
    </div>


    <?php endwhile; ?>

</div><!-- end forward-link -->
</li>
  • Consider checking out Wordpress codex page for the_loop that has great info
share|improve this answer
    
As always Amit, thank you for your help. I try to reference the Codex as often as possible, I guess I just didn't make the connection between the_loop and this particular context :/ –  user1255049 Aug 1 '12 at 18:30

If you query for a single post, you'll get the latest by default:

$latest = new WP_Query( array( 'posts_per_page' => 1 ) );
while( $latest->have_posts() ) :
    $latest->the_post();
    echo '<a href="' . get_permalink() . '>' . get_the_title() . '</a>';
endwhile;
share|improve this answer
    
Oh, good to know. How would I format what you've given me into a link? –  user1255049 Aug 1 '12 at 16:35
    
Thank you, both for your help. I've edited my original question to reflect what I have now- it seems close to what I'm needing, but something is still not quite right. If you take a look at the live site, you'll noticed that the middle section is now on top of the first blog section. –  user1255049 Aug 1 '12 at 17:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.