Archived topic
Related Post in Generatepress Using WP Show Post Plugin?
12 replies · Started by Suraj Katwal on December 5, 2019
Actually I want to use WP Show Post plugin to display related posts in the single post after content.
https://gpsites.co/merch/the-single-post/ ==> I was following the tutorial from the link. I didn't understand the
You will see in this line the 'related' list name:
$list = get_page_by_title( 'related', 'OBJECT', 'wp_show_posts' );
What I have done until now.
1. Install WPSP Plugin
2. Added a New List.
3. Used Hook to insert PHP Code.
But got error.
Thanks
Hi there,
you need to create a WP Show Posts list, and the Title you give the list must be related
Ya, I did it. Now I can show Related Posts but how to open all the links in a new tab?
Thanks
You would have to use javascript for that at the moment:
$( document ).on( 'click', '#wpsp-123 a', function(e) {
e.preventDefault();
var url = $(this).attr('href');
window.open(url, '_blank');
});
123 should be replaced with your list ID.
The code is not working.
WPSP List id 1002
$( document ).on( 'click', '#wpsp-1002 a', function(e) {
e.preventDefault();
var url = $(this).attr('href');
window.open(url, '_blank');
});
What I did
1. Elements > New Hook
2. <script>Above Code</script>
3. Settings > Hook > WP_Footer
4. Display Rules > All Singular
Thanks
There was an error on Console
Uncaught TypeError: $ is not a function
So fixed the error with small tweak
<script>
jQuery(function($){
$( document ).on( 'click', '#wpsp-1002 a', function(e) {
e.preventDefault();
var url = $(this).attr('href');
window.open(url, '_blank');
});
});
</script>
Thanks
Sorry about that! Glad it's working :)
Yeah!!! Thank you for the wonderful support. :)
No problem! :)
Now I am back with the tutorials on how to display related posts in GeneratePress Theme.
I hope this will help other users.
https://www.wplogout.com/display-related-posts-in-generatepress-theme/
Thank you.
Thanks for sharing!
Can I get the code to add related posts using tags? As we have code to display related posts using category.
Thank You
Got the code, Thanks