• I am working on a portfolio website. Whenever a portfolio piece is clicked, the user is taken to a page that shows details about that piece (i.e. more photos and information). There will also be previous and next navigation links to get to additional pieces. However, I want the previous and next navigation links to be a thumbnail photo of the next piece (custom field for that is thumbnail_photo). This is what I have so far:

    <?php
          $previous_post = get_previous_post();
          $next_post = get_next_post();
          $prev_value = get_post_meta( $previous_post->ID, 'materials', $single = true);
          $next_value = get_post_meta( $next_post->ID, 'thumbnail_photo', $single = true);
        ?>
    
               <p><?php echo $prev_value; ?></p>
               <p><?php echo $next_value; ?></p>

    I used ‘materials’ in the call for $prev_value since ‘materials’ is another custom field. I just wanted to see if it was actually working. It outputs the materials just fine, but it only outputs the ID number of the thumbnail_photo. I can’t get it to reference the file name so that I can output the actual image.

    I am using the Advanced Custom Fields plugin, so each image is stored as an image object. So this is how I would typically output a thumbnail image:

    <?php
          $image = get_field('thumbnail_photo);
          echo $image[sizes]["thumbnail"];  // thumbnail is a reference to wordpress' thumbnail media size
        ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • the backticks have to start at the left margin of the editor or have to be inline with the code; for some reason, if there are space characters before the backticks, the code marking fails. – backtick issue fixed n your post.

    please post in the plugin’s support section at https://www.ads-software.com/support/plugin/advanced-custom-fields

    why are you not using the same code for the ‘prev/next’ images?

    Thread Starter jasonTakesManhattan

    (@jasontakesmanhattan)

    Ok. I was confused about the backticks. I’ll post in the ACF support forum.

    I did try to output the image using the image object code, but that didn’t work either.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can't display thumbnail photo for next and previous posts’ is closed to new replies.