Below, you’ll find a detailed guide on how to add the Related Posts for WordPress Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Related Posts for WordPress Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Related Posts for WordPress Plugin and the shortcodes it provides:
"Related Posts for WordPress is a powerful plugin designed to engage your audience by displaying relevant content. It enhances user experience and boosts website navigation."
- [rp4wp]
Related Posts for WordPress [rp4wp] Shortcode
The Related Posts for WP (rp4wp) shortcode is a powerful tool that generates a list of related posts. This shortcode, when implemented, uses the post ID to fetch related posts. The ‘limit’ attribute controls the number of related posts displayed. The default value is -1, showing all related posts.
Shortcode: [rp4wp]
Parameters
Here is a list of all possible rp4wp shortcode parameters and attributes:
id
– The unique identifier of the post to display related posts for.limit
– Sets the maximum number of related posts to display.
Examples and Usage
Basic example – A simple usage of the rp4wp shortcode to display related posts for the current post.
[rp4wp /]
Advanced examples
Using the rp4wp shortcode to display related posts for a specific post by ID. In this example, the ID is 123.
[rp4wp id=123 /]
Using the rp4wp shortcode to limit the number of related posts displayed. In this example, the limit is set to 5.
[rp4wp limit=5 /]
Combining parameters in the rp4wp shortcode to display a limited number of related posts for a specific post by ID. In this example, the ID is 123 and the limit is 5.
[rp4wp id=123 limit=5 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [rp4wp]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'rp4wp', array( $this, 'output' ) );
Shortcode PHP function:
function output( $atts ) {
$atts = shortcode_atts( array(
'id' => get_the_ID(),
'limit' => -1
), $atts );
// Post Link Manager
$pl_manager = new RP4WP_Post_Link_Manager();
// Generate the children list
return $pl_manager->generate_children_list( $atts['id'], $atts['limit'] );
}
Code file location:
related-posts-for-wp/related-posts-for-wp/classes/hooks/class-hook-shortcode.php
Conclusion
Now that you’ve learned how to embed the Related Posts for WordPress Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply