[Support request] category specific side bar

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support category specific side bar

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #31315
    Mike
    Participant

    I can see how to globally choose categories in taxonomy. Is it possible to show only post in the same category on a page SIDEBAR when I have several categories?

    Thanks
    Mike Mahaffey

    #31332
    elvin
    Moderator

    Hi Mike,

    You’ll need a helper function for that.

    Tom wrote a PHP snippet for this.

    It’s this one:

    add_shortcode('dynamic_wpsp', function($atts){
        $queriedArchive = get_queried_object();
        $atts = shortcode_atts( array(
    			'id' => ''
    		), $atts, 'dynamic_wpsp' );
    
        $settings = array(
            'taxonomy' => $queriedArchive->taxonomy,
            'tax_term' => $queriedArchive->slug,
        );
     
        ob_start();
        wpsp_display( $atts['id'], $settings );
        return ob_get_clean();
    });

    It’s a snippet for a shortcode and the usage is [dynamic_wpsp id="1234"] where 1234 is the WPSP ID.

    #31389
    paul
    Participant

    Hi – sorry to hijack, I am trying to achieve the exact same thing. Have added the snippet to functions however the shortcode outputs my most recent posts from all categories rather than posts from the same category – do I need to apply any settings in the WPSP frontend?

    #31403
    elvin
    Moderator

    Hi – sorry to hijack, I am trying to achieve the exact same thing. Have added the snippet to functions however the shortcode outputs my most recent posts from all categories rather than posts from the same category – do I need to apply any settings in the WPSP frontend?

    Can you specify what page did you add the shortcode?

    The specific shortcode was written for WPSP added on archive page. If you use it on a static page, it won’t know what taxonomy to use because static pages normally don’t have taxonomy assigned to them.

    #31412
    paul
    Participant

    Hi Elvin – I want to use it on all standard posts on my site – is there a way to do this – let me know if I should open a new ticket for this.

    #31415
    elvin
    Moderator

    Well, we can modify the shortcode a bit so it takes the taxonomy terms of the current post.

    Try this:

    add_shortcode('dynamic_wpsp', function($atts){
    	
    	$posttax = 'category';
    	$queriedPost = get_the_terms( get_the_ID(), $posttax );
    	foreach ( $queriedPost as $tax ) {
    		$arg_slug = $tax->slug;
    	}
    	
        $queriedArchive = get_queried_object();
        $atts = shortcode_atts( array(
    			'id' => ''
    		), $atts, 'dynamic_wpsp' );
    
    	if(is_archive()){
    		$settings = array(
    			'taxonomy' => $queriedArchive->taxonomy,
    			'tax_term' => $queriedArchive->slug,
    		);
    	} 
    	
    	if(is_single()){
    		$settings = array(
    			'tax_term' => $arg_slug,
    		);
    	}
     
        ob_start();
        wpsp_display( $atts['id'], $settings );
        return ob_get_clean();
    });
    #31423
    paul
    Participant

    Works perfectly. Thanks

    #31429
    elvin
    Moderator

    No problem. Glad to be of any help. 😀

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.