- This topic has 5 replies, 4 voices, and was last updated 5 years, 6 months ago by
David.
-
AuthorPosts
-
September 26, 2020 at 7:46 am #1459879
Sanu Kumar
Hey there
I found PHP code for related posts but I am afraid where to paste because it can break my whole site so could you take a look at this and helps me to paste the code given below
<?php $tags = wp_get_post_tags($post->ID); if ($tags) { $tag_ids = array(); foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id; $args=array( 'tag__in' => $tag_ids, 'post__not_in' => array($post->ID), 'showposts'=>4, // Number of related posts that will be shown. 'caller_get_posts'=>1 ); $my_query = new wp_query($args); if( $my_query->have_posts() ) { echo '<div id="relatedposts"><h3>Related Posts</h3><ul>'; while ($my_query->have_posts()) { $my_query->the_post(); ?> <?php if ( has_post_thumbnail() ) { ?> <li><div class="relatedthumb"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?><?php the_title(); ?></a></div></li> <?php } else { ?> <li><div class="relatedthumb"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><img src="<?php echo get_post_meta($post->ID, 'Image',true) ?>" width="196" height="110" alt="<?php the_title_attribute(); ?>" /><?php the_title(); ?></a></div></li> <?php } ?> <?php } echo '</ul>'; } } $post = $backup; wp_reset_query(); ?>I want to show related posts just after the content
September 26, 2020 at 8:45 am #1460072Leo
StaffCustomer SupportHi there,
We can’t gaurantee that the code will work and won’t cause any issues as it’s not coming from us.
You can try to insert it using the
generate_after_contenthook using a hook element:
https://docs.generatepress.com/article/hooks-visual-guide/#single-post
https://docs.generatepress.com/article/hooks-element-overview/October 12, 2020 at 2:52 am #1484460Eaydman
Do you have a related post code snippet @leo ?
October 12, 2020 at 7:07 am #1484771David
StaffCustomer SupportHi there,
no we do not have a specific code for Related Posts.
You would be better off looking for a plugin that provides the specific kind of relationship you require.October 21, 2020 at 1:43 am #1498009Sanu Kumar
Hey there
Can I know – Is this website is using “WP Show Post” plugin to show their “Related Post”. If not, could you tell me the name of that plugin or it is custom coded?
October 21, 2020 at 3:59 am #1498144David
StaffCustomer SupportIt looks like it is custom developed.
-
AuthorPosts
- You must be logged in to reply to this topic.