Posted by AaronCampbell on August 22, 2009 · Leave a Comment
Version 0.3.2 of Efficient Related Posts was just released. Due to popular demand, it now has a shortcode to add add the list of posts anywhere shortcodes are supported in the loop. The readme was also updated to answer some of the common usage questions and to explain how to use the new shortcode.
The best place to find information is on the Efficient Related Posts page which is updated regularly. However, here are some of the new FAQs.
How can I add a list of related posts to my posts?
You can configure Efficient Related Posts to add related posts automatically in Settings -> Related Posts. Alternatively you can use the shortcode [relatedPosts] or the helper functions wp_get_related_posts() and wp_related_posts() in your theme files.
How exactly do you use the [relatedPosts] shortcode?
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"]
How do the theme helper functions work?
You can use wp_get_related_posts() and wp_related_posts() to display a list of related posts in your theme. They need to be used in “the loop” and the only difference is that wp_get_related_posts() returns the list and wp_related_posts() 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:
wp_related_posts(array('title'=>'Most Related Post', 'num_to_display'=>1))echo wp_get_related_posts(array('num_to_display'=>1, 'no_rp_text'=>'No Related Posts Found'))wp_related_posts(array('title'=>'Most Related Post', 'num_to_display'=>3, 'no_rp_text'=>'No Related Posts Found'))
Posted by AaronCampbell on April 15, 2008 · 46 Comments
Warning: Shortcodes are affected by Trac ticket 6444, which was fixed in WordPress 2.5.1.
First I touched on the topic in my first impressions of WordPress 2.5. Then I whined a little about the tickets relating to them, and eventually I released my Google Maps Plugin that uses them. In the end, WordPress’s new shortcodes are really nice.
What are they?
First of all, a shortcode called “mycode” can look like any of these:
[mycode]
[mycode foo="bar" id="123" color="red" something="data"]
[mycode]Some Content[/mycode]
[mycode]<p><a href="http://example.com/">HTML Content</a></p>[/mycode]
[mycode]Content [another-shotcode] more content[/mycode]
[mycode foo="bar" id="123"]Some Content[/mycode]
As you can see, shortcodes allow a user to put a code into a post or page, and a plugin can then easily handle those codes. They can be nested, contain content (including HTML), attributes, etc. Sounds great, but how can you leverage shortcodes for your benefit?
How can I use them?
You want to leverage the new, powerful shortcode system in WordPress 2.5, but where do you start?
Read more