Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
/*Breadcrumb*/

if ( ! function_exists( 'seobreadcrumbs' ) ) : 
function seobreadcrumbs() {
$separator = '›';
$home = 'Home';
echo '<div xmlns:v="http://rdf.data-vocabulary.org/#" class="seobreadcrumbs">';
global $post;
echo '  <span typeof="v:Breadcrumb">
You are Here :- <a rel="v:url" property="v:title" href="http://www.how2blog.in">Home</a>
</span> ';
$category = get_the_category();
if ($category) {
foreach($category as $category) {
echo $separator . "<span typeof=\"v:Breadcrumb\">
<a rel=\"v:url\" property=\"v:title\" href=\"".get_category_link($category->term_id)."\" >$category->name</a>
</span>";
}}
echo '</div>';}
endif;

function show_crumbs() {
if(is_single() || is_tag() || is_search() || is_404() || is_page() || is_category()) { ?>
<?php seobreadcrumbs(); ?>
<?php }}

add_action('thesis_hook_before_content','show_crumbs');
/* End*/

I use these codes to show breadcrumb trail. The problem I’m having with it is, some times its getting messed up let me clarify suppose I’ve category named

Social Media parent category is Facebook

When I publish a post under facebook It should show like

# Social Media >> Facebook

But some times facebook is coming 1st then Social Media 2nd like this:

# Facebook >> Social Media

And Google also displaying this way.

Can anybody help me regarding this?

share|improve this question
    
Does it sometimes show up with the child category before the parent category, or does it always show up that way? –  Chip Bennett Sep 1 '12 at 14:31

1 Answer 1

up vote 2 down vote accepted

My initial thought is that the issue is here:

$category = get_the_category();

If get_the_category() is returning categories in reverse-hierarchical order, then you can do this to put them back in order:

$category = get_the_category();
$category = array_reverse( $category );

However, I'm confused by this:

But some times facebook is coming 1st then Social Media 2nd...

If it is only happening sometimes, and not always, then I suspect that there is an issue somewhere else.

share|improve this answer
    
Oh my gosh it works :) I've no words left to tnx you... just want to say my hat goes off to you mate... God bless you... –  Arafin Shaon Sep 1 '12 at 15:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.