• I’ve set up a custom theme where at the end of every blog post it shows the next and previous posts. The design has the post’s featured image, title, category title and category icon.

    I can display everything but my if else statement which selects the correct category icon for the next and previous post is actually selecting it from the current blog post and not the next or previous.

    Mind you this code works for the actual post itself but I need the previous post’s category icon.

    Below is my code:

    <?php } ?>
    			<?php $nextPost = get_next_post(); ?>
    			<?php $nextThumb = wp_get_attachment_url( get_post_thumbnail_id($nextPost->ID) ); ?>
    			<?php if($nextPost) { ?>
    			<a href="<?php echo get_permalink( $nextPost->ID ); ?>">
    			<article class="unit w-1-2">
    			<div class="has-hover-overlay postRow" style="background-image: url(<?php echo $nextThumb; ?>);">
    			<div class="overlay"></div>
    			<div class="vAlign gl">
    			<div class="center">
    			<div class="circleContainer center" >
    			<?php $category = get_the_category($nextPost->ID); ?>
    			<?php
    			if ( in_category( 'mindfulness' )) {
    			echo '<img class="categoryIcon" src="http://localhost:8888/Meditation/wp-content/uploads/2015/05/mindfulnessIcon@2x.png" />';
    
    			} elseif ( in_category( 'meditation' )) {
    			echo '<img class="categoryIcon" src="http://localhost:8888/Meditation/wp-content/uploads/2015/05/meditation@2x.png" />';
    			} else {
    			// etc.
    			}
    			?>
    			</div>
    			<h3 class="categoryTitle uppercase"><?php echo $category[0]->cat_name; ?></h3>
    			<h2><?php echo $nextPost->post_title; ?></h2>
    			</div> <!-- unit center -->
    			</div> <!-- pl -->
    			</article>
    		</a>
  • The topic ‘How can I show previous post image with an if else statement?’ is closed to new replies.