Support » Plugin: Breadcrumb NavXT » Custom Breadcrumb for Archive Page

  • Resolved zwilson

    (@zwilson)


    I have an archive page /archive

    I built a single page app (SPA) on this page.

    The archive page breadcrumb is

    Client > Archive

    As part of the SPA, there’s a compare product tool. Once the user does a few things on the page, they are asyncronously built a new interface on the /archive page (/archive?_compare=A,B,C)

    We used the action bcn_before_fill to add Compare to the breadcrumb, creating:

    Client > Archive > Compare

    In the above, the only thing hyperlinked is “Client”.

    I’ve read every action / filter you have in your docs and can’t figure out how to make ‘Archive’ a link with any of your provided actions / filters.

    Can you please link me to the method or provide a small code sample as to how would accomplish this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter zwilson

    (@zwilson)

    Just to add to this, the filter I thought would do it was bcn_breadcrumb_url, but modifying the 2nd parameters, $type, was not giving me the result I thought it would.

    Plugin Author John Havlik

    (@mtekk)

    If you are using Breadcrumb NavXT 6.4, the best way to do this is to write an action for the bcn_after_fill hook (same API as bcn_before_fill, it just runs after the breadcrumbs array has been populated). You will want to traverse the breadcrumbs array looking for the one representing “Archive” (can check the title by calling get_title() on the bcn_breadcrumb object), and then use the set_linked(true) method (a member function of the bcn_breadcrumb object) on the bcn_breadcrumb object.

    Thread Starter zwilson

    (@zwilson)

    Perfect. Thank you.

    function _s_compare_breadcrumb_after($breadcrumb_trail_obj)
    {
        if (is_post_type_archive('archive') && get_query_var('_compare')) {
            foreach ($breadcrumb_trail_obj->breadcrumbs as $breadcrumb_trail) {
                if ($breadcrumb_trail->get_title() == 'Archive') {
                    $breadcrumb_trail->set_linked(true);
                }
            }
        }
    }
    add_action('bcn_after_fill', '_s_compare_breadcrumb_after');
    • This reply was modified 2 years, 7 months ago by zwilson.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Breadcrumb for Archive Page’ is closed to new replies.