Hello, currently Corona grabs the Related Posts by TAGS : ) Relations are defined by tags: if post tags match, the post will be displayed as related )
Is there a way to pull the related posts by CATEGORY instead?
Thanks in advance
Hello, currently Corona grabs the Related Posts by TAGS : ) Relations are defined by tags: if post tags match, the post will be displayed as related )
Is there a way to pull the related posts by CATEGORY instead?
Thanks in advance
Hey,
yes - in related-posts.php replace:
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = "";
foreach ($tags as $tag ) $tag_ids .= $tag->name.",";
$tag_ids = substr_replace($tag_ids ,"",-1);
$tag_ids = str_replace(" ", "-",$tag_ids);
if($tag_ids)
{
$my_query = new WP_Query("tag=$tag_ids&showposts=$postcount&ignore_sticky_posts=1&orderby=rand");
with:
$categories = get_the_category($post->ID);
$category_ids = '';
foreach ($categories as $category){
$category_ids .= $category->cat_ID;
}
if ($tags) {
if($category_ids)
{
$my_query = new WP_Query("cat=$category_ids&showposts=$postcount&ignore_sticky_posts=1&orderby=rand");Hey thanks for the help But..
When I replace the code as instructed, I get this error:
Parse error: syntax error, unexpected '}' in /home/........./wp-content/themes/EMSI/includes/related-posts.php on line 105
Any suggestions?
Thanks in advance!
Hi!
I missed an if-statement. I corrected the code above.
Regards,
Peter
You must log in to post.