Creating a related posts section in wordpress -


i'm trying create related post section in wordpress custom theme. objective here if user views post category show post category below. have attached image below.

http://i255.photobucket.com/albums/hh140/testament1234/relatedposts_zpsa830adfc.jpg

how achieve this? use wp_query this?

<?php query_posts('cat=6', 'posts_per_page=-4=-'); if(have_posts()) : while(have_posts()) :the_post(); ?> 

the code above sets category obtains post. 'cat'

solution of kwncc

    <div id="post-container" class="eleven columns alpha omega post">           <?php $postcategories = ''; while ( have_posts() ) : the_post(); ?>          <h2 class="post-title"><?php the_title() ?></h2>           <?php setpostviews(get_the_id()); ?> <!-- set post views -->           <ul class="meta-icons-large">             <li id="meta-author-large"><span><?php the_author_posts_link() ?> /</span></li>             <li id="meta-categories-large"><span><?php the_category(', ') ?> /</span></li>             <li id="meta-comments-large"><span><?php comments_number() ?> /</span></li>             <li id="meta-date-large"><span><?php the_time('f js, y') ?> /</span></li>             <li id="meta-views-large"><span><?php echo getpostviews(get_the_id()); ?></span></li> <!-- display post views -->          </ul>           <?php the_content(); ?>           <?php endwhile; ?>     </div>       <div id="related-posts-container" class="eleven columns alpha omega related-post">          <h2>related posts</h2>           <?php $postcatids = ''; foreach($postcategories $catindex => &$catvalue){             $postcatids .= $category->cat_id; if( $catindex < (count($postcategories)-1)){ $postcatids .= ', ';                        }             }             ?>           <?php query_posts('cat='.$postcatids, 'posts_per_page=4'); if(have_posts()) : while(have_posts()) { the_post(); } ?>           <div id="related-post-thumbnail-container" class="three columns alpha related-posts">               <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="permanent link <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>           </div>            <?php endwhile; endif; wp_reset_query();?>     </div>     <div id="comments-container" class="eleven columns alpha omega comments">         <?php comments_template('', true); ?>    </div>   </div> 

i'd suggest don't load related posts on page load because dramatically hurt website's performance.

the free wordpress plugin related posts wordpress automatically finds related posts (amongst others based on title) , caches them you, offering real related posts without hurting website's performance. after automatic linking done can, if required, manually add, edit or delete related posts. plugin comes template tags can display related posts anywhere in custom theme want. use rp4wp_children() in theme want related posts displayed.

you can give try via wordpress.org repo: http://wordpress.org/plugins/related-posts-for-wp/


Comments