Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #29454

    Hi Enfold team,

    Is it possible to show at a single blog page under “You might also like” posts based on the current post’s category?

    I think this can be done by changing the php code in /includes/related-posts.php. I tried, but was not able to actually show the tumbnails and your nice layout of the related posts.

    Is this also possible for the Avia Post NAV (avia-post-nav), to show the previous and next post of the same category?

    You would help me very much with this, thanks in advance!

    Regards, Fleur

    #140681

    1) Yes, open up related-posts.php and replace

    $tags               = wp_get_post_tags($this_id);

    with

    $tags 				= wp_get_object_terms( $post->ID, 'portfolio_entries');

    and

    $my_query = get_posts(
    array(
    'tag__in' => $tag_ids,
    'post_type' => get_post_type($this_id),
    'showposts'=>$postcount, 'ignore_sticky_posts'=>1,
    'orderby'=>'rand',
    'post__not_in' => array($this_id))
    );

    with

    if(get_post_type($this_id) == 'portfolio'){
    $my_query = get_posts(
    array(
    'tax_query' => array(
    array(
    'taxonomy' => 'portfolio_entries',
    'field' => 'id',
    'terms' => $tag_ids
    )
    ),
    'post_type' => get_post_type($this_id),
    'showposts'=>$postcount, 'ignore_sticky_posts'=>1,
    'orderby'=>'rand',
    'post__not_in' => array($this_id))
    );
    }else{
    $my_query = get_posts(
    array(
    'category__in' => $tag_ids,
    'showposts'=>$postcount, 'ignore_sticky_posts'=>1,
    'orderby'=>'rand',
    'post__not_in' => array($this_id))
    );
    }

    2) If you want to limit the post navigation to the current category you can use following code;

    add_filter('avia_post_nav_categories', 'use_same_category_filter');
    function use_same_category_filter($same_category)
    {
    $same_category = true;
    return $same_category;
    }

    - insert it at the bottom of functions.php. This code will only work for standard posts and it doesn’t support portfolio entries/post at the moment. This is indeed a bug in the software but not in our “software” or theme code but it’s a wordpress core bug/limitation: http://www.kriesi.at/support/topic/is-it-possible-to-create-two-completely-seperate-portfolios#post-108132

    #140682

    Thanks for your fast replay!

    Maybe I am missing something, because the first code you proposed (to show related posts of the same category under ‘You might also like’) doesn’t work for me. When applied exactly as you proposed (by changing php code) it does display nothing at all: no related posts at all, and also the sentence ‘You might also like’ is not visible anymore.

    I am working with a child-theme, so I copied the original file, changed the php code and placed it under enfold-child -> includes -> related-posts.php

    The second code works great: I now can navigate to the prev. and next post of the same category.

    Can you tell me or I have done something wrong, or maybe I can change the code a bit so that it is working?

    Thanks in advance!

    Regards, Fleur

    #140683

    Hi!

    I noticed I forgot to rewrite the category query itself. Please replace the entire code in related-posts.php with https://gist.github.com/InoPlugs/2fe563ced777b10522e3

    Best regards,

    Peter

    #140684

    Hi Peter,

    Your rewritten code for related posts works perfect! I’m very happy with your help and solution, thanks a lot!

    Have a nice Sunday.

    Best regards,

    Fleur

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

The topic ‘Related Posts based on category’ is closed to new replies.