开发者 | aaroncampbell |
---|---|
更新时间 | 2016年2月21日 07:42 |
捐献地址: | 去捐款 |
PHP版本: | 2.8 及以上 |
WordPress版本: | 4.4 |
You can configure Efficient Related Posts to add related posts automatically in Settings -> Related Posts. Alternatively you can use the shortcode [relatedPosts] or the you can use the 'erp-show-related-posts' action or 'erp-get-related-posts' filter in your theme files.
To use the default settings (from Settings -> Related Posts) you just need to
add [relatedPosts]
to your post or page where you want to list to be. You can
also add some attributes to it such as num_to_display (Number of related posts
to display), no_rp_text (Text to display if there are no related posts), and
title (Title for related posts list, empty for none) like this:
[relatedPosts title="Most Related Post" num_to_display="1"]
[relatedPosts num_to_display="1" no_rp_text="No Related Posts Found"]
[relatedPosts title="Try these related posts:" num_to_display="3" no_rp_text="No Related Posts Found"]
You can use the 'erp-show-related-posts' action or 'erp-get-related-posts' filter to display a list of related posts in your theme. They need to be used in "the loop" and the only difference is that the 'erp-get-related-posts' filter returns the list and the 'erp-show-related-posts' action echos the list. You can also pass an associative array of arguments to it such as num_to_display (Number of related posts to display), no_rp_text (Text to display if there are no related posts), and title (Title for related posts list, empty for none) like this:
<?php do_action('erp-show-related-posts', array('title'=>'Most Related Post', 'num_to_display'=>1)); ?>
<?php echo apply_filters('erp-get-related-posts', array('num_to_display'=>1, 'no_rp_text'=>'No Related Posts Found')); ?>
<?php do_action('erp-show-related-posts', array('title'=>'Most Related Posts', 'num_to_display'=>3, 'no_rp_text'=>'No Related Posts Found')); ?>
The theme helper functions still exist, but the new actions and filters mentioned above are preferred. Hopefully the helper functions will be removed in the future, so PLEASE don't use them.
No, Efficient Related Posts finds all the posts related to the one being saved, and if the current post is more closely related to one of those posts than the least related post that is currently stored, it re-processes that post. Simple right? Well, maybe it's not so simple, but rest assured that your posts can and will show the posts they are most related to regardless of post date.
Posts are considered related based on tags. This may be extended in the future, but I wanted to keep the queries as clean as possible.
[relatedPosts]
shortcode as another way to add a list of related posts to a post or pageesc_html
with wp_specialchars
for those still on 2.7.x