George Hess

  • Archive
  • RSS
  • Contact

Q:Regarding WordPress:
I was wondering if you knew how to display the excerpt for next and previous posts in the side bar if you are on a blog page?

Anonymous

WordPress has a get_previous_post() and a get_next_post() function that return most of the information pertaining to the next/prev posts.

<?php
$prev_post = get_previous_post();
if ($prev_post) {
echo '<a href="' . get_permalink($prev_post->ID) . '">&larr; '. $prev_post->post_title . '<br />' . $prev_post->post_excerpt . '</a>';
}

$next_post = get_next_post();
if ($next_post) {
echo '<a href="' . get_permalink($next_post->ID) . '">'. $next_post->post_title . ' &rarr;<br />' . $next_post->post_excerpt . '</a>';
}
?>

    • #web dev
  • 1 year ago
  • Permalink
  • Share
    Tweet
← Previous • Next →

Portrait/Logo

About

I'm a writer of sorts and designer of websites with a specialty in mobile and front end development …more

Me, Elsewhere

  • @georgehess on Twitter
  • Facebook Profile
  • georgehess on Vimeo
  • georgehess on Flickr
  • Google
  • My Skype Info
  • Linkedin Profile
  • georgehess on github

Twitter

loading tweets…

Following

  • RSS
  • Random
  • Archive
  • Contact
  • Mobile

© George Hess …but does anybody even care?. Effector Theme by Carlo Franco.

Powered by Tumblr