Mediaturner.com

This site will continue to grow with a collection of tips, articles,resources on numerous topics and areas of interest.

  • Home
  • Archives
  • Privacy Policy
  • Links
  • About
  • Contact
  • WordPress
  • Downloads
  • Videos
RSS FeedSubscribe to RSS feed!
RSS CommentsSubscribe to RSS Comments!

Subscribe via EmailSubscribe through Email

Recent Post

  • Forza 4 – My first Paint and Decal designs
    Forza 4 – My first Paint and Decal designs
    on 5th Nov 2011 in Videos
  • AVG Free Edition
    AVG Free Edition
    on 15th Apr 2011 in Downloads
  • Display Related Post In WordPress Without Plugin
    Display Related Post In WordPress Without Plugin
    on 13th Mar 2011 in WordPress
  • The best free graphic editing software
    The best free graphic editing software
    on 3rd Feb 2011 in Downloads
  • CCleaner optimizes Windows to run faster
    CCleaner optimizes Windows to run faster
    on 12th Dec 2010 in Downloads

Recent Comments

  • Sabrina: Great tutorial, I found it ver
    on How to split WordPress post into separated pages

Archives

  • November 2011
  • April 2011
  • March 2011
  • February 2011
  • December 2010
  • November 2009

Most Popular

  • Forza 4 – My first Paint and Decal designs
  • Display Related Post In WordPress Without Plugin
  • How to split WordPress post into separated pages
  • AVG Free Edition
  • CCleaner optimizes Windows to run faster

Featured Video

Categories

  • Downloads
  • Videos
  • WordPress

Tags

    Gaming Anti-Virus WordPress Tutorials Windows
Home » WordPress » Display Related Post In WordPress Without Plugin

Display Related Post In WordPress Without Plugin

Installing lot’s of plugins makes your blog attractive, but can be a security issue and may become outdated. In this article, I will show you how to add related post without a plugin. The two simplest ways is by Tag which is a keyword which describes all or part of a post and by Category which are posts with similar content. Just open the single.php file in your theme and add this bit of code where you want the related posts to show up…

How to show related posts by tags.

<?php
$tags = wp_get_post_tags($post->ID);
if ($tags) {
	$tag_ids = array();
	foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;

	$args=array(
		'tag__in' => $tag_ids,
		'post__not_in' => array($post->ID),
		'showposts'=>5, // Number of related posts that will be shown.
		'caller_get_posts'=>1
	);
	$my_query = new wp_query($args);
	if( $my_query->have_posts() ) {
		echo '<h3>Related Posts</h3><ul>';
		while ($my_query->have_posts()) {
			$my_query->the_post();
		?>

			<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
		<?php
		}
		echo '</ul>';
                wp_reset_query();
	}
}
?>

How to show related posts by category.

<?php
$categories = get_the_category($post->ID);
if ($categories) {
	$category_ids = array();
	foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;

	$args=array(
		'category__in' => $category_ids,
		'post__not_in' => array($post->ID),
		'showposts'=>5, // Number of related posts that will be shown.
		'caller_get_posts'=>1
	);
	$my_query = new wp_query($args);
	if( $my_query->have_posts() ) {
		echo '<h3>Related Posts</h3><ul>';
		while ($my_query->have_posts()) {
			$my_query->the_post();
		?>
			<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
		<?php
		}
		echo '</ul>';
                wp_reset_query();
	}
}
?>
March 13, 2011 | Posted by Ninetto | WordPress | Leave a comment 
Tags: WordPress Tutorials

Related Posts

If you enjoyed reading this article, please check out other articles below:

How to hide WordPress Version to Improve Security

How to hide WordPress Version to Improve Security
One of the easy ways hackers can determine if your website can be easily compromised is to look at Wordpress version. It is because as Wordpress.org publishes a new version, it will state an update ...

How to split WordPress post into separated pages

How to split WordPress post into separated pages
Most Internet readers do not read a website page as they would a book, so the shorter the better. Even if this means separating or splitting the posts into 4 or 5 pages. Even if search ...

Leave a Reply

Click here to cancel reply.




Copyright © 2012 Mediaturner.com · All rights reserved · Powered by WordPress & Tim Hortons · Log in