How To Show Category Related Posts When single.php WordPress Trick

Please log in or register to like posts.
News

How To Show Category Related Posts When single.php WordPress Trick

Hi Guys, In This Article I Will Show Your How You Can Make WordPress Category Related Posts From single.php file. The Functions Output The Current Posts Category Related Posts. When Your Website Have a Category Called WordPress Tricks, When You Post This Category Minimum Two Posts. When Your Read The Post You Can See The Category Related Posts. In You On Your WordPress Others Category Posts Like WordPress SEO, The Function Will Output WordPress SEO Category Related Posts. Just We Need To Make File With a Folder e.g /themename/includes/post-related.php After Your Created The Folder In Your Theme File Simply Copy Past The Below Code.

Related Posts

<div class="related_post">

<h6>Related Posts</h6>

<ul>

<?php

          $category = get_the_category(); //get first current category ID

          $this_post = $post->ID; // get ID of current post

          $posts = get_posts('numberposts=5&category=' . $category[0]->cat_ID . '&exclude=' . $this_post);

          foreach($posts as $post) { ?>

<li>

<?php

// Related post thumbnail.


if ( has_post_thumbnail() ) {

          the_post_thumbnail( 'thumbnail' );

}

else {

          echo '<img width="320" height="200" src="' . get_bloginfo( 'template_url' ) . '/images/no-thumbnail.png" class="attachment-thumbnail wp-post-image" alt="No image" />';

} ?> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> <p><?php the_time( get_option( 'date_format' ) ) ?> - <?php the_time( get_option( 'time_format' ) ) ?></p>

</li>

<?php } wp_reset_postdata(); ?>

</ul>

</div>

Above Code We Was Call a Image And It Will Be Shown When A Post Don’t Has Thumbnail Image. Simply Make Or Design A No Thumbnail Image Better Download From Google Image Search. After Download Or Designed Go To Your Theme File From Hosting Location: /themename/images/ Upload The Image Here.

Now Go To The single.php File From Theme Folder. The Open This File For Edit and Past The Below Code Before <?php get_footer();?>

<?php get_template_part( 'includes/post-related' ); ?>

Now You Are Done To Showing Category Related Posts From Your Post Category. You Can Read More WordPress Tips Tricks From Below.

CallBack Better WordPress Comments Template – Customize WordPress Comments
How To Change Default Role Name in WordPress User Profile
How To Make WordPress Post Views Count Without Plugin – WordPress
How To Highlight Author Comment in WordPress Using Only CSS
10+ Most Wanted WordPress Tips, Tricks, and Hacks – HowTrick
TrickBD WordPress Theme Download For Free – Nulled

[ads]

Nobody liked ?

Leave a Reply

Your email address will not be published. Required fields are marked *