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 as much as possible with WordPress plugins lines of code that lead to the same result. (Note, however, that some code in functions.php add it particularly seriously affect performance of the server)

WordPress Related Post Plugin

Plugins "Related Posts"Can be replaced with the function below, if we choose that page article to be 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] <? 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 displayed.
'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>';
[/ Php]


Concrete example.

The page article ". "Are listed as the related articles referring to WordPress, viruses, databases, exploits.

WordPress Exploit - cleaning infected files, and SQL Server security. - Stealth Settings 

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

Show Related Post in WordPress Without a Plugin.

How to add Related Post in WordPress without using plugins

About the author

Stealth LP

Founder and editor Stealth SettingsIn 2006 date.
Experience on Linux operating systems (especially CentOS), Mac OS X, Windows XP> Windows 10 and WordPress (CMS).

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment is processed.