Related Post in wordpress custom theme

Related Post in wordpress custom theme

<aside class="widget widget-recent-post">
<h2 class="widget-title">Recent Posts</h2>

<ul class="recent-post-list">

<?php
    $query = ['post_type' => 'post', 'post_status' => 'publish', 
    'posts_per_page' => 5, 'post__not_in' => array($post->ID)];
    $movieQuery = new Wp_Query($query);
    $i = 0;

       while($movieQuery->have_posts()){
           $movieQuery->the_post();
           $thumbPath = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
           if($thumbPath){
              $thumb = $thumbPath[0];
           }
           else{
              $thumb = '';
            }

?>

<li class="recent-post-list-li postID<?php echo $post->ID; ?>" id="postID<?php echo $post->ID; ?>"> 
<a class="recent-post-thum" href="<?php the_permalink(); ?>">
<img src="<?php echo $thumb; ?>" class="img-fluid" alt="">
</a>

<div class="pbmit-rpw-content">
<span class="pbmit-rpw-date">
<a href="<?php the_permalink(); ?>">
<?php echo get_the_date('D M j'); ?>
</a>
</span>

<span class="pbmit-rpw-title">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</span>

</div> 

</li>

<?php } ?>

</ul>

</aside>

 

Leave a Reply