Related post is very useful for a blog for show related article to visitors. for show related post there are huse of plugins for free. but use of plugins is not good for a wordpress blog. it is the main cause of delayed loading time for wordpress. if you want to display related post without any kinds of plugins in your wordpress blog. then you can follow my post carefully.
1. First of all copy this code:
now paste and save it in your themes 'single.php' files which location where you can show your related post(at the end of all post).2. now copy this code:
IF PROBLEM COPY HERE
paste and save it in your themes 'style.css' file.
3. now load a single post and see that, your related post is displaying after single post with thumbnail like this:
So, enjoy yourself. thanks.
1. First of all copy this code:
IF PROBLEM COPY HERE<div class="relatedbox"> <h2> Related Post </h2> <ul class="rpul"> <?php $category = get_the_category($post->ID); $current_post = $post->ID; $posts = get_posts('numberposts=5&category=' . $category[0]->cat_ID . '&exclude=' . $current_post); foreach($posts as $post) : setup_postdata( $post ); ?> <li> <?php if ( has_post_thumbnail() ) { the_post_thumbnail('portfolio'); } else { ?> <img src="<?php bloginfo('template_directory'); ?>/images/default.gif" /> <?php } ?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <br/> <font color="green">Tuner:</font><font color="red"> <?php the_author();?> </font> <span> <span> <?php the_date('j F, Y');?> </span> <span> <?php comments_popup_link ('Leave a comment' , '1 comment' , '% comments'); ?> </span> <?php echo getCrunchifyPostViews(get_the_ID()); ?> </span> </li> <?php endforeach; wp_reset_postdata();?> </ul> </div> <!--relbox-->
now paste and save it in your themes 'single.php' files which location where you can show your related post(at the end of all post).2. now copy this code:
.relatedbox { padding-top: 10px; padding-left: 10px; border: 1px solid #bbbdde; border-radius:.1em 0 0 0; margin-bottom: 10px; } .rpul {} ul.rpul li{padding: 5px; border-bottom: 1px solid #ddd; display: block; min-height: 80px;} ul.rpul li:last-child{padding: 5px; border-bottom: 0px} ul.rpul img{float: left; padding: 5px; border: 1px solid #bbbdde; border-radius:.1em 0 0 0; margin-right: 5px; width: 60px; height: 60px;} ul.rpul p{ display: block; font-size: 13px} ul.rpul p a{display: inline-block; font-size: 13px; color: #000} ul.rpul a{font-size: 15px;}
IF PROBLEM COPY HERE
paste and save it in your themes 'style.css' file.
3. now load a single post and see that, your related post is displaying after single post with thumbnail like this:
So, enjoy yourself. thanks.
(f)
ReplyDelete