Wordpress breadcrumbs issue
I have a breadcrumb in my website that's not working properly. When I go to a product like
Equipment» Products» Railing» Heavy Railing» Waterproof» Superrail 2000
it shows me this breadcrumb properly as it should. However when I get to the same product through "Non-waterproof" instead of "Waterproof" it shows me this same breadcrumb (so basicly, it only follows 1 category).
I wanted to check this in the settings of my breadcrumb plugin, but it shows me the message "Your settings are out of date. Migrate now.", and my supervisor has adviced me to not "migrate" it.
Does anyone have a solution that uses either a plugin or custom code that works with multiple categories?
Edit:
I'm working with WP 3.6, which I'm not allowed to update. The URL looks something like this http://www.website.com/product/asl6109t32/, which means I can't use the URL to generate the breadcrumb.
If I may, here is some nifty code snippet for creating breadcrumb navigation, place it in your theme's functions.php
file:
/***********************************************************
* wsf_breadcrumbs() - Shows breadcrumbs in template
***********************************************************/
function wsf_breadcrumbs( $sep = '/', $label = 'Browsing' ) {
global $post, $front_page;
// Do not show breadcrumbs on home or front pages.
// So we will just return quickly
if((is_home() || is_front_page()) && (!$front_page))
return;
// Create a constant for the separator, with space padding.
$SEP = ' ' . $sep . ' ';
echo '<div class="breadcrumbs">';
echo $label;
echo wsf_make_link( home_url(), 'Home', get_bloginfo('name'), true ) . $SEP;
if(is_single()) {
the_category(', '); echo $SEP;
}
elseif (is_search()) {
echo 'Search results - ';
}
elseif (is_404()) { //Wordpress bug
echo 'Error 404 (Page not found) ';
}
elseif (is_author()) {
echo 'Articles posted by author ';
}
elseif (is_tag()) {
echo 'Posts tagged ';
}
elseif (is_year()) {
echo get_the_time('Y');
}
elseif (is_month()) {
echo get_the_time('F').' ('.get_the_time('Y').')';
}
elseif (strstr($_SERVER['REQUEST_URI'],"wp-login.php")) {
echo 'Administration panel';
}
elseif(is_page()) {
$parent_id = $post->post_parent;
$parents = array();
while($parent_id) {
$page = get_page($parent_id);
$parents[] = wsf_make_link( get_permalink($page->ID), get_the_title($page->ID) ) . $SEP;
$parent_id = $page->post_parent;
}
$parents = array_reverse($parents);
foreach($parents as $parent) {
echo $parent;
}
}
// Wordpess function that echoes your post title.
the_title();
echo '</div>';
}
/*------------------------------------------------------*/
/* Create breadcrumb navigation
/*------------------------------------------------------*/
/***********************************************************
* Helper Functions for template coding
***********************************************************/
function wsf_make_link ( $url, $anchortext, $title=NULL, $nofollow=false ) {
if ( $title == null ) $title=$anchortext;
$rel = ($nofollow == true) ? ' rel="nofollow"' : $rel = '';
$link = sprintf( '<a href="%s" title="%s" %s>%s</a>', $url, $title, $rel, $anchortext );
return $link;
}
/*------------------------------------------------------*/
/*------------------------------------------------------*/
Then, in your footer.php
file, invoke the function like this:
<div id="breadcrumb">
<?php wsf_breadcrumbs('','') ?>
</div>
链接地址: http://www.djcxy.com/p/39186.html
上一篇: 搜索结果中的WordPress面包屑
下一篇: WordPress的面包屑问题