How to add Related Post in WordPress without using plugins

For "Related Post"Or"Related articles”Are a series of PluginLinks to more or less sophisticated, but in the end all do the same thing. Displaying a page (in a post) on the blog headlines that match the topic of the article is made listing. This is useful both for SEO as well as userAllowing quick access to articles that are on the same topic as the one on the page is printing.

It is known that a large number of PluginSites can negatively influence unuei page loading time and also creates additional tables in the database.

A good idea would be to replace the plugins as much as possible WordPress with lines of code leading to the same result. (Be careful though, because some of the code used especially in functions.php can seriously affect server performance)

WordPress Related Posts Plugin

PluginsRelated Posts”Can be replaced with the function below, if we choose to be on the article page displayed headlines containing same tags with the job of doing the listing. Using this criterion relationship can add the code below in file single.php the theme used on the blog.

<?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>';
}
}
?>

Concrete example.

In the article page ". ” are listed as related articles those that refer to WordPress, viruses, databases, exploits.

WordPress Exploit - Clean up virus files, SQL and server security. - Stealth Settings

The function is tested on WordPress 3.3.1 but is also compatible with newer versions of WordPress 2.x.

- Show Related Post in WordPress Without a Plugin.

Founder and editor Stealth Settings, from 2006 to the present. Experience on operating systems Linux (in particular CentOS), Mac OS X, Windows XP> Windows 10 si WordPress (CMS).

How to » Noteworthy » How to add Related Post in WordPress without using plugins
Leave a Comment