Support » Plugin: Related Posts by Taxonomy » Link to all related posts

  • Resolved vocotech

    (@vocotech)



    Hi keesiemijer,

    Thank you for this great plugin.

    I’m showing 3 related posts to my visitors. But I also want to give them a link to all related posts of current taxonomy. Like this:

    Here are the 3 related posts on current taxonomy:

    Related post 1
    Related post 2
    Related post 3

    If you want to display all the related posts on this taxonomy, please click here.

    How can I create this kind of a link, with shortcode?

    Thanks in advance.

    • This topic was modified 9 months ago by  vocotech.
    • This topic was modified 9 months ago by  vocotech.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author keesiemeijer

    (@keesiemeijer)

    Hi vocotech

    What should happen after you click the link? Refresh the page and display the remaining related posts? Or go to an taxonomy archive page with posts from the taxonomy?

    Here’s how you can add a link after the display of the shortcode. The link doesn’t have a target yet because I don’t know where it should link to.

    Put this in your theme’s (child) functions.php file.

    
    add_filter( 'related_posts_by_taxonomy_shortcode_atts', 'shortcode_add_taxonomy_link' );
    
    function shortcode_add_taxonomy_link( $args ) {
    	$taxonomies = km_rpbt_get_taxonomies( $args['taxonomies'] );
    	if ( ! isset( $taxonomies[0] ) ) {
    		return $args;
    	}
    
    	// Get the first taxonomy
    	$tax = get_taxonomy( $taxonomies[0] );
    
    	// The taxonomy label
    	$tax_label = $tax->labels->menu_name;
    
    	$tax_link = "<a href='#'>{$tax_label}</a>";
    
    	// Taxonomy link (with the closing div from $args['before_shortcode'])
    	$args['after_shortcode'] = $tax_link . '</div>';
    
    	return $args;
    }
    

    btw:
    consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost. Or create a plugin with the code above.

    vocotech

    (@vocotech)

    Hi keesiemijer,

    Thank you for the quick answer. Much appreciated.

    I’m using Directory theme (Premium Press Theme). I want to use this link through the advanced search function (as a search query).

    Theme example page: http://dp1.wlthemes.com/?s=

    I have more than 100 posts on some taxonomies. So, I don’t want to display all the related posts to my visitors. I want to show them only a few related posts. And then,

    If you want to see all the related posts, please click here” message.

    If current category is: example-category
    Taxonomy 1 is: taxonomy1
    Current Taxonomy 1 value is: exampletax1
    Taxonomy 2 is: taxonomy2
    Current Taxonomy 2 value is: exampletax2

    Search results link like this on my theme:

    http://mysite.com/?s=&s=&tx_listing=example-category&tx_taxonomy1%5B%5D=exampletax1&tx_taxonomy2%5B%5D=exampletax2&advanced_search=yes

    • This reply was modified 9 months ago by  vocotech.
    • This reply was modified 9 months ago by  vocotech.
    vocotech

    (@vocotech)

    I apologize for this complicated request. Your plugin really cool and do its job very well. Is there a way to generate such links with a shortcode (if you recommend another plugins instead of ‘Related Posts by Taxonomy’, may be it can be solve my problem also. Thank you again.

    Plugin Author keesiemeijer

    (@keesiemeijer)

    I think I understand what it is you want to do. Unfortunately this is a bit outside of the scope for the support I provide here. I also don’t know of any plugins that does this out of the box.

    I think it should be possible with this plugin. And I would still use the related_posts_by_taxonomy_shortcode_atts filter to build the (search) link query and add it after the shortcode.

    Maybe you should consider hiring someone so that you can give them direct access to the site for a far more efficient fix than I can provide here.

    I can, of course, still help if there are specific questions you (or the developer) might have.

    Hi keesiemijer,

    Thank you. I apologize for the delay. I will consider what you said on your previous message. Much appreciated for this plugin and your help.

    Kind Regards

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Link to all related posts’ is closed to new replies.