简体   繁体   中英

Related Posts in WordPress

I'm interested in modifying a template in a wordpress install to show related posts ... in my case, I think I'd be fine with just showing the latest 5 posts in the current post's category.

How would one do that without installing a plugin ? I would rather modify the template in this instance

I've poked around on google trying to find and haven't been successful at finding the right API calls to make this happen.

Like mentioned by the other posters you need an plugin to make this work. The reason ist, that there is no API in wordpress to get the related posts. What the plugins bsically do, is building a database out of all words in all postings and display the postings with the most common words.

See this question for some explanation on how stackoverflow is doing this. The book Programming Collective Intelligence has a good explanation on some of the more advanced approaches to the related posts problem.

There is a Related posts by category plugin, at http://wordpress.org/extend/plugins/related-posts-by-category/ . Install it in WP admin and modify your theme. The following code generates a series of five li's containing links to the posts.

<?php
related_posts_by_category(
      array(
        'orderby' => 'post_date',
        'order' => 'desc',
        'limit' => 5,
        'echo' => true,
        'before' => '<li>',
        'inside' => '',
        'outside' => '',
        'after' => '</li>',
    //  'rel' => 'nofollow',
        'type' => 'post',
    //    'message' => 'no matches',
        'showthis' => true
      )
    );
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM