Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author John Havlik

    (@mtekk)

    I see your problem, I’m not exactly sure on how I’ll fix it (whether I’ll just add an ID tag, or if I’ll add something like tax-ID and post-ID where ID is replaced with the ID number).

    For the near term, you can add in your own custom template tag using the bcn_template_tags filter. From the Breadcrumb NavXT documentation:

    Three parameters are available to filters for this hook, the first is the replacements array, which is the item being filtered. This array is a key value pair, where the key is the template tag, and the value is the value to replace the tag with. The second is types array for the breadcrumb. The third is the id of the resource the breadcrumb represents.

    So, you should be able to do something like this:

    add_filter('bcn_template_tags', 'my_custom_bcn_tags', 10, 3);
    function my_custom_bcn_tags($replacements, $types, $id)
    {
    	if(in_array('taxonomy', $types))
    	{
    		$replacements['%id%'] = 'tax-' . $id;
    	}
    	else if(in_array('post', $post))
    	{
    		$replacements['%id%'] = 'post-' . $id;
    	}
    	return $replacements;
    }

    Note that I did not test the above code, so it may have minor syntax errors.

    Thread Starter sbn128

    (@sbn128)

    Thanks for help. It works. Will include this in the next plugin update?

    Plugin Author John Havlik

    (@mtekk)

    Something like this will show up in the next version. Though I have not decided if I will use the post-ID and tax-ID syntax, or if I will use bcn-post-ID and bcn-tax-ID. There may be class collisions with the main post body classes and people that style based off of just .post-ID and .tax-ID may unintentionally style the breadcrumbs.

    Hi,

    We are running into a similar problem / slightly different, but I think almost the same solution.

    We we have under the taxonomies a ‘Listings category’. We would like to keep the category in the breadcrumb, but the page it goes to by default : /listing-category/*the category*

    This page is not one we would like to use, but on the listing overview page we already have everything we would like to use. We could send the url there using the filter. Like this:
    href=”/listing-page/?list-cat=%****%”
    The current values like %title% etc. don’t work as this ?list-cat= uses the category slug.

    I take it from the documentation this is achievable, but my knowledge for this is limited and I do not fully understand how this would work.

    Your example gives me some idea, as to what we can place in the functions.php but this is something with id’s and I cant figure out how to get the slugs with this?

    I hope someone can point me in the right direction.

    Kind regards,

    Martijn

    Plugin Author John Havlik

    (@mtekk)

    The template tags discussed here probably will not do what you want. If you want to modify the URL that Breadcrumb NavXT is using for a particular breadcrumb, you will probably want to write a filter that hooks into bcn_breadcrumb_url. You will need to use the passed in parameters $type and $id to determine what resource the breadcrumb is representing and then return the $url you want for that breadcrumb.

    Hi,

    Sorry I don’t fully understand what to do here.

    I can return the correct title with %title% but I can’t get the slug using something like %slug%. It seems to me, since the title is returned correctly getting the slug of that same thing wouldn’t be to hard, but I dont know how.

    The %link% actually returns the slug, but with the entire url. I just need the slug from the specific taxonomie.

    Kind regards,

    Martijn

    After some more reading and trail & error, I’ve found that this following will work.

    add_filter('bcn_template_tags', 'my_custom_bcn_tags', 10, 3);
    function my_custom_bcn_tags($replacements, $types, $id)
    {
    	if(in_array('taxonomy', $types))
    	{
    		$term = get_term( $id, $taxonomy );
    		$slug = $term->slug;
    		$replacements['%slug%'] = $slug;
    	}
    	else if(in_array('post', $post))
    	{
    		$replacements['%slug%'] = $id;
    	}
    	return $replacements;
    }

    I guess it will not work for post yet, but as I only use this for taxonomies, this will do the trick.

    Kind regards,

    Martijn

    Plugin Author John Havlik

    (@mtekk)

    I was thinking of a solution more akin to what I posted in this thread:

    https://wordpress.org/support/topic/customize-breadcrumb-post-category-links?replies=2

    as that will be more robust (you’re kinda hijacking the template tags for things they’re not meant to do). But, if you have something working, great!

    In regards to handling posts, you will need to look at the $types array as well since its contents vary depending on the item the breadcrumb represents (a post, a taxonomy archive, etc).

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Include %slug% or %id% in Taxonomies class.’ is closed to new replies.