How do we add reported post in WordPress without using plugins

For “Related Post” or “Related articles” are a series of pluginthat are more sophisticated, but in the end they do about the same thing. Displays on a page (in a post) on the blog the titles of the articles that correspond as a subject with the article in which the listing is made. Is a useful function both for SEO as well as for user, allowing quick access to articles that are on the same subject as the one on the page on which the listing is made.

It is known as a large number of plugin-uri can inflict negative the loading time of one page and in addition it creates additional tables in the database.

A good idea would be to replace as much as possible WordPress plugins with code lines that will lead to the same result. (Attention, however, because some codes especially in functions.php can seriously affect server performance)

WordPress Related Post Plugin

The plugins of “Related Posts” can be replaced with the below function, if we choose to be on the article page to be displayed the titles of articles which contain the same tags with the post in which it makes listing. Using this relationship criterion we can add the code below to the file single.php of 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.

On the article page “.” Those related to WordPress, viruses, databases, exploits are listed as related articles.

WordPress Exploit – Curatare fisiere virusate, SQL si securizare server. - 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.

Founder and editor Stealth Settings, din 2006 pana in prezent. Experienta pe sistemele de operare Linux (in special CentOS), Mac OS X , Windows XP > Windows 10 si WordPress (CMS).

Home Your source of IT tutorials, useful tips and news. How do we add reported post in WordPress without using plugins
Leave a Comment