Related post by category displays same set of posts all the time!?
-
Hi Everyone,
In an effort to silo my site, I am trying to show related posts by category, so that posts in different categories dont link to each other (which is essential to siloing).
I found the below code. It works to some extend. However, it seems to show only the same posts ll the time (no matter what post page you are on). Also, it also displays a link back to the actual post that you are on as related posts.
I have very minimal knowledge of coding. What, if anything can be added to this code to…
1- Make it so that it doesn’t always display the same set of 5 posts.
2- So that it doesn’t display a link back to the current post?…Thank you very much in advance.
<!-- Start Category Link Code --> php if ( is_single() ) { ?> <ul> php foreach((get_the_category($post->ID)) as $category) { ?> php $catVal = $category->cat_ID; } $IDOutsideLoop = $post->ID; global $post; $myposts = get_posts('category='.$catVal.'&numberposts=5&order=ASC'); foreach ($myposts as $post) { ?> php if($IDOutsideLoop == $post->ID) { echo " class=\"current\""; } ?>> php the_permalink() ?>"> </li> php }; ?> </ul> php } ?> <!-- End Category Link Code -->
- The topic ‘Related post by category displays same set of posts all the time!?’ is closed to new replies.