Is there any way to direct users to other related blog posts when they’re reading a certain post of yours?
Hi Sharon,
Thank you for writing in, try adding a Recent Posts shortcode on the bottom of your posts. Filter the Recent Posts shortcode with the category of the post so it only shows the posts that are related to the current posts.
If that does not work for you, please test the top Related posts plugins from here and see which one suits your needs.
Cheers!
Is there any way to do this to all posts without manually inserting?
Hi Sharon,
Do you mean with the Recent Posts shortcode? You can follow the same guide provided here.
Replace the [cs_gb id=123]
on the code with your own Recent Posts shortcode.
Refer for the name actions here to place your Recent Posts either before or after the content.
Please note that the provided code serves only as a guide, and we won’t be able to provide support on modifying it to exactly adhere to your needs.
Thanks,
Oh cool! Is there a way to make it so all the posts from one category will show recent posts of that category though? Versus placing that code there overall
Hey Sharon,
You can filter your posts by category by entering the slug of your desired category in the shortcode e.g:
[recent_posts count="1" orientation="vertical" category="remember"]
But this would show the posts from the category you specify in the shortcode and not category posts you’re viewing. Achieving this might be possible with custom development, but this would be outside the scope of support we can offer. You may wish to consult a developer to assist you with this. X is quite extensible with child themes, so there are plenty of possibilities.
Thanks for understanding. Take care!
Hi - I’m getting confused at what code I should enter.
The other day I tried entering this in functions.php just to test it out:
function add_global_blocks_single_post(){
echo do_shortcode(’[recent_posts count=“3” orientation=“vertical” category=“digital-nomad”]’);
}
add_action(‘x_after_the_content_end’, ‘add_global_blocks_single_post’);
But it gave me an error. This is also not what I want because I want to make it so any post with category digital-nomad would return other recent posts under digital-nomad.
Any advice? Can you provide me the correct code? I can also provide the login for my site if that will help. Thanks!
Hello Sharon,
Your code is correct and should have no problem:
function add_global_blocks_single_post(){
echo do_shortcode('[recent_posts count="3" orientation="vertical" category="digital-nomad"]');
}
add_action('x_after_the_content_end', 'add_global_blocks_single_post');
Can you recall what is the error message that will display?
Thanks.
But besides that this is also not what I want because I want to make it so any post with category digital-nomad would return other recent posts under digital-nomad, and any post with category passive-income would return other recent posts under passive-income.
Hey Sharon,
We’re sorry for the wrong information here. The Recent Post shortcode will not display Related Posts. We do not have that feature built-in in any of our products yet.
You will need a third-party plugin for this. Just based on experience, you can try Jetpack Related Post as it automatically displays related posts at the end of the single blog post. It’s also whitelisted by hosts like WP Engine. See https://wpengine.com/support/disallowed-plugins/#relatedpost
Please just note that it’s not a recommendation. Feel free to search or use other third-party plugins.
-----------------------------------------------------------------------------------
If you wish to continue using the custom code provided here, you can still display category based recent post by using the in_category WordPress conditional. It goes like the following. See the if
statment in the code below which is a part or should be a part of the function given previously.
if (in_category('music')) {
echo do_shortcode('[recent_posts count="3" orientation="vertical" category="digital-nomad"]');
}
As you might already know, you’ll need to repeat that for each category you have so if you don’t like coding, I’d recommend hiring a web developer to do this for you moreover that manual coding is prone to user error and PHP errors could take down your site.
Thanks.
I keep getting this error - can you advise?
Hey Sharon,
That means that there’s a syntax error in your PHP. I’d recommend hiring a developer to fix the PHP errors.
Thanks.
Wouldn’t the error have already been present and mess up my site if it were there before I added this code?
Hi Sharon,
The easiest way to check where the error is coming from is process of elemination. Try to switch from child theme to main theme. See if that error is still there once you are using main theme. If it’s gone, it is something from the child theme. To know which part, please try to activate child theme again. Then remove all your custom codes and put it back one by one. Check after adding each code.
Hope this helps.
No. If there’s an error in the PHP you’ve just written, WordPress won’t accept it and thus you see the message. That’s why I recommended that you hire a developer especially that this is not an issue with our theme.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.