Support » Fixing WordPress » fetching the excerpts for next/previous posts

  • Resolved splosion



    I’m trying to fetch the excerpts for next and previous posts but can’t seem to figure out how. next_post_link() doesn’t seem to offer the excerpt as an argument, and get_next_post() has no documentation, so I am unsure what I can pass to it. Seems like that should be the one to use.

    What I’m trying to do is have the next and previous posts available as links via the thumbnail I insert into the excerpt for each post, so I’ll have images as links instead of words. Thanks for any suggestions.

Viewing 3 replies - 1 through 3 (of 3 total)
  • there is maybe something in here:

    Thank you, I was able to adapt the information to my need. Below is the code if anyone is interested. It will grab the assigned thumbnail of the post and make the image itself the link to said post.
    <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>

    …and here is the code I’m using to show the thumbnails in single.php as links.

    It tests to see if there next or previous posts, and if so, adds in the thumbnails linked via permalinks to the next or previous post.

        	$nextPost = get_next_post(true);	//Gets next and previous posts and their URIs
    		$nextURI = get_permalink($nextPost->ID);
    		$prevPost = get_previous_post(true);
    		$prevURI = get_permalink($prevPost->ID);
        <?php if ($nextPost || $prevPost): 		//Tests if there are any previous OR next posts. If yes, inserts a nav spacer bar along with next/prev thumbs ?>
    			<?php if($nextPost) {
    				echo '<a href="' . $nextURI . '">';
    				$nextthumbnail = get_the_post_thumbnail($nextPost->ID, array(122,122) ); echo $nextthumbnail;
    				echo '</a>';
    			}; ?>
    			<?php if($prevPost) {
                	echo '<a href="' . $prevURI . '">';
    				$prevthumbnail = get_the_post_thumbnail($prevPost->ID, array(122,122) ); echo $prevthumbnail;
    				echo '</a>';
    			}; ?>
    	<?php endif; ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘fetching the excerpts for next/previous posts’ is closed to new replies.