Tagged: 

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #9797

    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

    #65879

    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 . ',';
    }

    $category_ids = (substr($category_ids,-1) == ',') ? substr($category_ids, 0, -1) : $category_ids;

    if ($tags) {

    if($category_ids)
    {
    $my_query = new WP_Query("cat=$category_ids&showposts=$postcount&ignore_sticky_posts=1&orderby=rand");

    #65880

    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!

    #65881

    Hi!

    I missed an if-statement. I corrected the code above.

    Regards,

    Peter

    #65882

    Hey Dude!

    This just works if you use only one category. Is there a way to show related posts if a post got more than one category? Please see my problem here: http://www.kriesi.at/support/topic/related-posts-not-showing-up-when-post-is-connected-to-more-than-one-category

    THX and Regards

    Job

    #65883

    Hey!

    I changed the code a bit. It should work with more than one category now.

    Best regards,

    Peter

    #65884

    Hey Peter,

    works fine now. Thanks a lot!

    Regards,

    Job

    #65885

    Hi!

    Great :)

    Regards,

    Peter

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Related Posts in Corona’ is closed to new replies.