Related Posts, Without any Plugin!
Hi everybody. You can show your related posts without any plugin. It’is important for visitors i think. Because they can discover your blog with that area. This code shows your same-tagged posts. Some plugins do this but why use plugin if you have a powerfull theme :). You can change posts number too. Lets Begin…
With this function/recipe you will change your core single.php file. If you have no information about WordPress coding -so you’re a newbie- you can get some support if you send a mail to me. Don’t touch your single.php if you don’t know about WordPress
We will change our themes single.php. Make bakcup and be careful. After backup open single.php and copy this code after loop or content.
Here is the code;
<?php
//for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {
echo 'Related Posts';
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
}
?>
Save single.php. And then refresh your page. Related Posts are display after content. :) If you change ‘showpost=5‘ (the 5 is post number) 5 to 4,6,9,etc. Related posts number will change.
That’s All! Have a nice day!
- General
Filed Under
-
Categories
Tags
elseif SEO disable hide revision wprecipes usage article title nickname short title comments menu button sidebar remove menu trick captions tutorial breadcumbs show rss changes doctype ns4 tooltip theme yoast funciton ie rewiew comment list social bar NeoEase hidden file login form safari without plugin attachment google docs delay time description zlib library today CMS query version wp_posts comment tabs spam free 2010 security hole steal theme develop guest article numbers highlight searched text categories in two columns image database comment_cookie easy life crawl update theme edit returning shortcode furl happy new year no-index protect archives.php change subscribe hacks echo functioıns bio color wthout plugin Facebook mysql archive have_posts newsletter Wordpress contact form 7 tweet wordpress forums randomize visitors Premium themes fetch feed scheduled system firewall mood spiders browser detect Turkey server google xml sitemaps future posts ads protected sor_column close Wordpress search WP Loop WpFunc modify del.icio.us rss feed file output firefox colored tag cloud month word count digg commenting blog recipe wp_nav_menu sql injection weekly chrome footer question 2009 holiday function generator Settings menu area exploit wp version fallback_cp article content search engine exploit scanner solution edit link change recent commen editor expration template bandwith wordpress 3.0 queries auto save non-complex noindex links hotlinking random post long titles plugin writer funcitons delicious spped up your blog wp_categories_menu time link integrate java Udegbunam blog stats title highliht writer style.css image upload html old posts day tim thumb index.php single Yahoo Blogroll css comments.php spam commets archive template system health wp_page_menu change theme db Joomla javascript custom field wordpress dashboard source social networks comment form author name search searched text disable caching post date php search term the_loop phpmyadmin 15 days old year posts robots post_status PDF first else feedburner user_login more link new year highlight Google adsense div didim header.php archive.php login name post editor customizable titles request vuvuzela sticky posts reCAPTCHA area jquery Functions sliding more collection get image featured.php Google post attachments visitor moderate footer.php list category me comment number buttons share on facebook show mood Related posts style body bubletooltips hide content Popular Posts if magazin style sidebar.php footer links social bookmark date button comment editing non-premium themes comments.php hacks post_type dropdown menu theme_location Serkan Algur archives menu sistemi WorPress compress plugin manager site jump link first image .htaccess blog security menu_order search terms reddit wp-admin remove inline comments problem core file security scan contact Widget single.php Twitter vectorss RSS XHTML IE6 message response time kaisercrazy upgrade custom title publish time featured function_exists category_description social Tinymce private command widgetize sql date author schedule login panel extra area functions.php Platinum SEO Pack dashboard XHTML tags disable captions code hyperlink post categories thumbnail iphone feed plugins page category delay ie8 timestampRecent Comments
- John, sorr... »
- John on Catch the First Imagenevermind ... »
- John on Catch the First ImageWhere do y... »
- ok, thank ... »
Archives
Blogroll
Google Ads















Made by Symmetric Web
Distributed by Smashing Magazine
No comments yet!