Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Elvin

    (@ejcabquina)

    Hi there,

    That code isn’t exact created to be dynamically switching between related posts for single pages and latest posts for home page.

    You’ll need a plugin that does exactly that purpose.

    Or,

    Do something like the article provided here.
    https://www.wplogout.com/display-related-posts-in-generatepress-theme/

    Which is similar w/ my answer here –
    https://wpshowposts.com/support/topic/what-is-the-best-tactics-to-show-really-related-posts-on-wp-show-posts/#post-31731

    Thread Starter aliamirifard

    (@aliamirifard)

    Thanks Alvin

    This code is very convenient for me but it does not work

    Shortcode works but shows the latest posts as before
    I want exactly the same short code that shows the related posts according to the category
    Thank you for your help

    Plugin Support Elvin

    (@ejcabquina)

    Is it only for single posts pages?

    If so, here’s one that will only work on posts pages. What this does is, it gets the first category term it can get from the post and displays posts from that category term. Which is technically “related posts”.

    add_shortcode('dynamic_wpsp', function($atts){
        
        $atts = shortcode_atts( array(
    			'id' => ''
    		), $atts, 'dynamic_wpsp' );
    
        if( is_single() ) {
            $cats =  get_the_category();
            $cat = $cats[0];
            $settings = array(
                'taxonomy' => 'category',
                'tax_term' => $cat->slug,
            );
        } 
        
        ob_start();
        wpsp_display( $atts['id'], $settings );
        return ob_get_clean();
    });
    Thread Starter aliamirifard

    (@aliamirifard)

    GREAT it worked,
    Now I have the (recent posts) on the main page, and (related posts) in the single-post with one wpsp
    fantastic
    Thanks Elvin

    ??? ??? ??

    • This reply was modified 2 years, 10 months ago by aliamirifard.
    • This reply was modified 2 years, 10 months ago by aliamirifard.
    • This reply was modified 2 years, 10 months ago by aliamirifard.
    Plugin Support Elvin

    (@ejcabquina)

    Nice one. No problem. ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show related posts on single pages’ is closed to new replies.