Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$5
Breadrcumbs: Get current category/slug path only for post
I'm having a slight problem with breadcrumbs.
When a post is assigned to two or more categories, my breadcrumbs then display all the categories associated with the post instead of just the current category path as exhibited in the URL.
Example,
"My Post Title" is assigned "Category A" and "Category B"
I am viewing "My Post Title" in "Category B" (www.example.com/category-b/my-post-title)
The breadcrumbs show:
You are in: Category A >>
Category B >> My Post Title
Instead of,
You are in: Category B >> My Post Title
So to recap,
I need to show breadcrumbs that are relative to the path of the URL including any categories/sub-categories instead of all categories associated with the "My Post Title".
As you can see showing all categories/sub-categories associated with a post in breadcrumbs can be confusing for visitors.
Thank you,
Wprrrrring
This question has been answered.
Wordpressing | 06/13/11 at 12:27am
Edit
(2) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
06/13/11
12:32amFahd Murtaza says:Please share your category breadcrumb code. And do you have any preference to which category you want to show in the breadcrumb navigation?
Previous versions of this answer: 06/13/11 at 12:32am
- 06/13/11 12:35am
Wordpressing says:Hi Fahd,
I want to show the current breadcrumb path so that it matches the slug/permalink structure in your browser address bar.
So if a post has multiple categories it needs to only show the current path relative to where the user is viewing the post.
The function I am using in my functions.php file is:
// breadcrumbs
function the_breadcrumb() {
if (!is_home()) {
echo '<a href="';
echo get_option('home');
echo '">';
bloginfo('name');
echo "</a> » ";
if (is_category() || is_single()) {
the_category('title_li=');
if (is_single()) {
echo " » ";
the_title();
}
} elseif (is_page()) {
echo the_title();
}
}
}
I've tried several other custom functions written by other WP developers but all produce the same result.
Thank you - 06/13/11 12:41am
Fahd Murtaza says:Got it, I am working on it.
I have just one thing for you to take note of.
On a category page, you can get the name and ID of the current category from path. But I am not sure how to know once category name for a unique category if you are on a single page.
What is your permalink structure as it can help. - 06/13/11 12:42am
Fahd Murtaza says:My bad,
Please ignore my last question.
I am viewing "My Post Title" in "Category B" (www.example.com/category-b/my-post-titl
I got it. - 06/13/11 2:02am
Fahd Murtaza says:This should work
Line # 92 of your code
#blog-title {font-size:64px;line-height:60px;letter-spacing:-2px;width:585px;display:inline;float:left; display:none; visibility:hidden;}
- 06/13/11 2:03am
Fahd Murtaza says:sorry, my last response was not for you.
- 06/13/11 2:16am
Fahd Murtaza says:Enjoy your new breadcrumbs :)
You can remove the comments.
// breadcrumbs
function the_breadcrumb() {
if (!is_home()) {
echo '<a href="';
echo get_option('home');
echo '">';
bloginfo('name');
echo "</a> » ";
if (is_category() || is_single()) {
// the_category('title_li=');
//print_r(get_the_category());
$_SERVER['REQUEST_URI_PATH'] = preg_replace('/\\?.*/', '', $_SERVER['REQUEST_URI']);
// echo "<br/>server=".$_SERVER['REQUEST_URI_PATH'];
$url_segments= split('/',$_SERVER['REQUEST_URI_PATH']);
$total = count($url_segments);
// echo "<br/>count= ". $total;
if(is_single())
{
$category_slug = $url_segments[$total-3];
}
else if(is_category())
{
$category_slug = $url_segments[$total-2];
}
// echo "<br/>Category slug = ". $category_slug;
$cat_info= get_category_by_slug( $category_slug );
// echo "<pre>";
// print_r($cat_info);
// echo "</pre>";
// Type cast for easy handling
$cat_info = (array) $cat_info;
$cat_name = $cat_info['name'];
//echo "<br/>Category name = ". $cat_name;
echo $cat_name;
if (is_single()) {
echo " » ";
the_title();
}
} elseif (is_page()) {
echo the_title();
}
}
}
- 06/13/11 11:47am
Fahd Murtaza says:Let me know if you tried that code.
- 06/15/11 12:18pm
Fahd Murtaza says:Let me know if you still need help. Did my solution work as I want to mature it based on your feedback.
- 06/13/11 12:35am
-

Last edited:
06/13/11
1:05amDenzel Chia says:Hi,
Have you tried this plugin?
http://wordpress.org/extend/plugins/breadcrumb-trail/
Thanks.
Denzel
This question has expired.
Christianto voted on this question.
Current status of this question: Completed
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
