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

    (@mtekk)

    Breadcrumb NavXT can be called within the loop. However, by default Breadcrumb NavXT caches the breadcrumb trail. So, if you were to place bcn_display() in the search results loop, you would only get the breadcrumb trail for the first result repeated for every result. For situations like this, the fourth argument for the bcn_display functions was added. To achieve what you want to do, you’ll want to use something like bcn_display(false, true, false, true) instead of the usual bcn_display().

    Thread Starter Lukasz

    (@wpfed)

    Great thanks!

    I gave it a shot, using bcn_display_list( false, true, false, true ) since it takes the same parameters as bcn_display but I still had to add $wp_query->is_singular = true; so it behaves as single post for each result:

    global $wp_query;
    	// backup.
    	$old_singular_value = $wp_query->is_singular;
    	// change.
    	$wp_query->is_singular = true;
    	if ( function_exists( 'bcn_display_list' ) ) :
    		?>
    		<nav class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/" aria-label="<?php esc_attr_e( 'breadcrumb' ); ?>">
    			<ol class="breadcrumb mb-1 small">
    				<?php bcn_display_list( false, true, false, true ); ?>
    			</ol>
    		</nav>
    		<?php
    	endif;
    	// restore.
    	$wp_query->is_singular = $old_singular_value;

    Also for anyone else wondering you then have to edit the search template in the plugin config to something like this:

    <span property="itemListElement" typeof="ListItem"><a href="%link%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>
    <span class="%type%">%htitle%</span>
    • This reply was modified 5 years, 2 months ago by Lukasz.
    • This reply was modified 5 years, 2 months ago by Lukasz.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Breadcrumbs in search results’ is closed to new replies.