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

    (@mtekk)

    So, there are a couple of ways you could do this, depending on what sort of interface you want. If you want to just add something in front of the title text, then the bcn_breadcrumb_title filter can be used and you can add something in front of the title as needed. The other option is creating a custom breadcrumb template tag using the bcn_template_tags filter and then you can place that tag in your breadcrumb templates where ever you want the extra text to show up.

    Hi,

    I have a similar issue but not sure the bcn_template_tags would solve it (maybe I don’t understand it correctly though).

    In my case, I use two taxonomies:

    • category (custom, but works like the native one)
    • tag (native)

    Using ACF, I created a parent > child relation between the category and the tag by adding a relation field to the tag.

    Let say I have the following hierarchy :

    - Category A
    	- Tag A.1
    	- Tag A.2
    	- ...

    Now in my breadcrumb, when I visit any one of the “child” tags, I would like it to look like this :

    Home > Category A > Tag A.1
    Home > Category A > Tag A.2

    But for now I get :

    Home > Tag A.1
    Home > Tag A.2

    As I understand, the bcn_template_tags “just” allows us to add a tag that will be replaced by a value, but what i need is to inject a hierarchy level in the breadcrum, based on the ACF field.

    Is it doable?

    Plugin Author John Havlik

    (@mtekk)

    @improvedline Yeah, the bcn_template_tags filter isn’t what you want. In fact, using ACF may not be the correct way of doing this as well (unless it lets you set the term parent for a term to be of any term, of any taxonomy). Since 7.0, Breadcrumb NavXT supports type juggling for taxonomy terms, so you can just set the term_parent property for the term and Breadcrumb NavXT should follow it (setting Category A as the parent of Tag A.1 and Tag A.2 it should ‘just work’ if the tag taxonomy is set as the hierarchy for the post type in the Breadcrumb NavXT settings page). You just have to establish that term parent hierarchy.

    Hi @mtekk

    Thanks for your quick answer, unfortunately, I have no choice but to use ACF to setup my hierarchy as in my case, it must be between to different taxonomies (which is not supported natively by WP).

    I also use Permalink Manager Pro on the same website and I use this hierarchy to fine tune the urls. It works well, now I just need to match the breadcrumb with my url structure.

    @suil: sorry for incrusting myself in your thread, but i thought our issue is similar.

    In case it can be usefull to anyone, I took the liberty to invertigate a little further the plugin code to understand how the breadcrumb is compile and managed to hook on the bcn_after_fill filter to achieve what I needed.

    Here is the code I’m using:
    I try to comment it as mutch as possible to help people understand and modify it as needed (but I won’t provide any suppport 🙂 ).

    /**
     * Add parent "gamme" in the breadccrumb hierarchy for tag 
     * the hierarchy is set using ACF taxonomy field (to link the post_tag to a gamme)
     * 
     * If you need to test it in your own hierarchy, don't forget to replace the taxonomies slugs 
     * (aka: "post_tag" and "gamme")
     */
    add_action('bcn_after_fill', 'ca_add_hierarchy_to_breadcrumb');
    function ca_add_hierarchy_to_breadcrumb( $breadcrumb_trail ){
        // Can't have more than 2 entries in the breadcrumbs at this point for our usecase
        if(count($breadcrumb_trail->breadcrumbs) != 2) {
            return;
        }
    
        $first_key = 0;
        $last_key = count( $breadcrumb_trail->breadcrumbs ) - 1;
    
        $first_entry = $breadcrumb_trail->breadcrumbs[$first_key]; // bcn_breadcrumb object
        $last_entry = $breadcrumb_trail->breadcrumbs[$last_key]; // bcn_breadcrumb object
    
        // Check if last entry type match what we are looking for
        if( in_array( 'post_tag', $first_entry->get_types() ) ) {
            // 0 - Check if term has, indeed a parent
            // warning: I use an ACF function here because I know it is active
            $gamme_id = get_field( 'etiquette_gamme_parent', 'post_tag_' . $first_entry->get_id() ); 
            // Hierarchy not set: nothing to do
            if( empty( $gamme_id ) ) {
                return;
            }
            // 1 - Remove last entry 
            // don't worry it is stored in the $last_entry variable so we'll be able to reinject it later
            unset($breadcrumb_trail->breadcrumbs[$last_key]);
            // 2 - identify parent object 
            $gamme = get_term($gamme_id, 'gamme');
            // 3 - Inject parent in tray
            $breadcrumb_trail->add(new bcn_breadcrumb($gamme->name, NULL, array('gamme'), get_term_link($gamme, 'gamme'), $gamme_id, true)); 
            // 4 -Reinject last entry in tray
            $breadcrumb_trail->add($last_entry);
        }
    }
    
    Plugin Author John Havlik

    (@mtekk)

    Just a heads up, while WordPress doesn’t natively support term parent relationships outside of the same taxonomy in the editor, the WordPress backend supports it. You should just have to provide your own GUI element and code to set the parent term as desired (there are probably plugins that let you do this, but I’m not familiar with any).

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How do I add a field from Advanced Custom Fields before the page names?’ is closed to new replies.