[resolved] fetching the excerpts for next/previous posts (4 posts)

  1. splosion
    Posted 5 years ago #


    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.

  2. Michael
    Part-Time Forum Moderator
    Posted 5 years ago #

    there is maybe something in here:

  3. splosion
    Posted 5 years ago #

    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>

  4. splosion
    Posted 5 years ago #

    ...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; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic