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.

Uhm, this is quite a weird problem and I'm trying to make sure that I explain it well enough so that you understand what I'm talking about.

So, I'm using breadcrumbs in my header area. It all works fine. However, when you type in a search, it only SOMETIMES displays the actual search result in the breadcrumbs. It's supposed to look like that: Home » Blog » Search results for "lorem" View it live.

However, if the first search result (the one that is being displayed on top of all others) is a static page instead of a blog post, the breadcrumbs display it this way: Home » Blog » Page View it live. It's still shown correctly in the tab of my browser. Only the breadcrumbs seem to get confused.

This is the code snippet I use for the breadcrumbs:

function dimox_breadcrumbs() {

  $delimiter = '<span class="delimiter">&raquo;</span>';
  $home = 'Home'; // text for the 'Home' link
  $before = '<span class="current">'; // tag before the current crumb
  $after = '</span>'; // tag after the current crumb

  if ( !is_front_page() || is_paged() ) {

    echo '<div id="crumbs">';

global $post;
$divider = $delimiter;
if (is_home()) $divider = '';
$homeLink = get_bloginfo('url');
echo '<a href="' . $homeLink . '" rel="nofollow">' . $home . '</a> ' . $delimiter . ' <a href="http://www.zoomingjapan.com/blog/" rel="nofollow">Blog</a> ' . $divider . ' ';

    if ( is_category() ) {
      global $wp_query;
      $cat_obj = $wp_query->get_queried_object();
      $thisCat = $cat_obj->term_id;
      $thisCat = get_category($thisCat);
      $parentCat = get_category($thisCat->parent);
      if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
      echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after;

    } elseif ( is_day() ) {
      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
      echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
      echo $before . get_the_time('d') . $after;

    } elseif ( is_month() ) {
      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
      echo $before . get_the_time('F') . $after;

    } elseif ( is_year() ) {
      echo $before . get_the_time('Y') . $after;

    } elseif ( is_single() && !is_attachment() ) {
      if ( get_post_type() != 'post' ) {
        $post_type = get_post_type_object(get_post_type());
        $slug = $post_type->rewrite;
        echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';
        echo $before . get_the_title() . $after;
      } else {
        $cat = get_the_category(); $cat = $cat[0];
        echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
        echo $before . get_the_title() . $after;
      }

    } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
      $post_type = get_post_type_object(get_post_type());
      echo $before . $post_type->labels->singular_name . $after;

    } elseif ( is_attachment() ) {
      $parent = get_post($post->post_parent);
      $cat = get_the_category($parent->ID); $cat = $cat[0];
      echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
      echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
      echo $before . get_the_title() . $after;

    } elseif ( is_page() && !$post->post_parent ) {
      echo $before . get_the_title() . $after;

    } elseif ( is_page() && $post->post_parent ) {
      $parent_id  = $post->post_parent;
      $breadcrumbs = array();
      while ($parent_id) {
        $page = get_page($parent_id);
        $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
        $parent_id  = $page->post_parent;
      }
      $breadcrumbs = array_reverse($breadcrumbs);
      foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
      echo $before . get_the_title() . $after;

    } elseif ( is_search() ) {
      echo $before . 'Search results for "' . get_search_query() . '"' . $after;

    } elseif ( is_tag() ) {
      echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;

    } elseif ( is_author() ) {
       global $author;
      $userdata = get_userdata($author);
      echo $before . 'Articles posted by ' . $userdata->display_name . $after;

    } elseif ( is_404() ) {
      echo $before . 'Error 404' . $after;
    }

    if ( get_query_var('paged') ) {
if (is_home()) echo ' ' . $delimiter . ' ';
      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
      echo __('Page') . ' ' . get_query_var('paged');
      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
    }

    echo '</div>';

  }
} // end dimox_breadcrumbs()

I already talked to the creator of the code, but he also has no clue why this is ocurring. I hope somebody has at least a clue so that I can work on it?

Thanks a lot! :)

share|improve this question
add comment

1 Answer 1

Try to change this part:

echo $before . 'Search results for "' . get_search_query() . '"' . $after;

To this:

$searchTerm = get_search_query()
echo $before . 'Search results for "' . $searchTerm . '"' . $after;
share|improve this answer
    
So, i understand that fixed that? gr8 man - good luck :) –  Sagive SEO Oct 23 '11 at 0:43
    
Sorry, your code is producing the following syntax error: unexpected T_ECHO –  japanworm Oct 23 '11 at 3:01
    
If I add a ";" after the get_search_query, then the syntax error disappears, but the code doesn't do anything, the problem is not solved. –  japanworm Oct 23 '11 at 3:03
add comment

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.