0

The current Prev and Next buttons in a wordpress theme that I'm using is rendered from this function in functions.php:

if ( !function_exists( 'krunk_post_navigation' ) ) {
    function krunk_post_navigation( $direction, $posting, $term ) {

        $post_navigation = '';

        if( $posting ) {

            $post_navigation .= '<a class="post-navi-' . $direction . ' clearfix" href="' . get_permalink( $posting->ID ) . '">' .
                                    '<div class="post-navi-inner">';
                                        $post_navigation .= '<div class="post-navi-' . $direction . '-info">' .
                                            '<div class="table-cell-middle">' .
                                                '<div class="post-navi-label"><i class="fa fa-long-arrow-left"></i>' . esc_attr( $term ) . '<i class="fa fa-long-arrow-right"></i></div>' .
                                            '</div>' .
                                        '</div>' .
                                    '</div>' .
                                '</a>';


        }

        return $post_navigation;
    }
}

How do I integrate the following code to the function above so that there will be a thumbnail of the previous and next posts too along with the arrows?

$previousPost = get_previous_post();
$previousThumbnail = get_the_post_thumbnail( $previousPost->ID );
$nextPost = get_next_post();
$nextThumbnail = get_the_post_thumbnail( $nextPost->ID );

1 Answer 1

1

Without more context it's hard to be sure, but it looks like this function is being called twice: once for each link ($direction="next" and $direction="previous"). The $posting parameter looks to be the next or previous post. If my assumptions are correct, you need to get the thumbnail for that post:

$thumbnail = get_the_post_thumbnail( $posting->ID );

and then insert it into the $post_navigation string being created. I would put it at the end of line 8 and see how that works:

$post_navigation .= '<a class="post-navi-' . $direction . ' clearfix" href="' . get_permalink( $posting->ID ) . '">' . $thumbnail .

Note that get_the_post_thumbnail() will return an image sized to the 'post-thumbnail' dimensions, and will likely be too large. So you may need to define a new size and pass that as a parameter to get_the_post_thumbnail(). You will also probably need CSS to style the link to accommodate the image.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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