WordPress breadcrumb with custom post type

Previously I’ve wrote The simplest breadcrumb for WordPress, it was limited to a simple website or blog, however, when I search around the net, I found another interesting breandcrumb with better functionality, by DimoxWordPress Breadcrumbs Without a Plugin.

Breadcrumb

However, since WordPress 3.0 released, there are a few functions that developers find interesting and helpful. Then the breadcrumb is not that handy anymore.

This is the code I find from by Dimox:

function dimox_breadcrumbs() {

  $delimiter = '»';
  $name = 'Home'; //text for the 'Home' link
  $currentBefore = '<span class="current">';
  $currentAfter = '</span>';

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

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

    global $post;
    $home = get_bloginfo('url');
    echo '<a href="' . $home . '">' . $name . '</a> ' . $delimiter . ' ';

    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 $currentBefore . 'Archive by category '';
      single_cat_title();
      echo ''' . $currentAfter;

    } 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 $currentBefore . get_the_time('d') . $currentAfter;

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

    } elseif ( is_year() ) {
      echo $currentBefore . get_the_time('Y') . $currentAfter;

    } elseif ( is_single() && !is_attachment() ) {
      $cat = get_the_category(); $cat = $cat[0];
      echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
      echo $currentBefore;
      the_title();
      echo $currentAfter;

    } 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 $currentBefore;
      the_title();
      echo $currentAfter;

    } elseif ( is_page() && !$post->post_parent ) {
      echo $currentBefore;
      the_title();
      echo $currentAfter;

    } 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 $currentBefore;
      the_title();
      echo $currentAfter;

    } elseif ( is_search() ) {
      echo $currentBefore . 'Search results for '' . get_search_query() . ''' . $currentAfter;

    } elseif ( is_tag() ) {
      echo $currentBefore . 'Posts tagged '';
      single_tag_title();
      echo ''' . $currentAfter;

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

    } elseif ( is_404() ) {
      echo $currentBefore . 'Error 404' . $currentAfter;
    }

    if ( get_query_var('paged') ) {
      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>';

  }
}

Now that it has a great functionality, with main category and parent page. However, it doesn’t work with custom post type, as they are new taxonomy

Add:

elseif ( get_post_type() == 'Musics' ) { // Post type name
echo get_the_term_list($post->ID, 'Artist', '', ', ', ' ' . $space . ' '); // New taxonomy
echo $before;
the_title();
echo $after;
}

It helps on getting the new taxonomy. Overall, the code look something like this:

function dimox_breadcrumbs() {

  $delimiter = '»';
  $name = 'Home'; //text for the 'Home' link
  $currentBefore = '<span class="current">';
  $currentAfter = '</span>';

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

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

    global $post;
    $home = get_bloginfo('url');
    echo '<a href="' . $home . '">' . $name . '</a> ' . $delimiter . ' ';

    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 $currentBefore . 'Archive by category '';
      single_cat_title();
      echo ''' . $currentAfter;

    } 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 $currentBefore . get_the_time('d') . $currentAfter;

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

    } elseif ( is_year() ) {
      echo $currentBefore . get_the_time('Y') . $currentAfter;

    } elseif ( get_post_type() == 'Musics' ) {
      echo get_the_term_list($post->ID, 'Artist', '', ', ', ' ' . $space . ' ');
      echo $before;
      the_title();
      echo $after;

    } elseif ( is_single() && !is_attachment() ) {
      $cat = get_the_category(); $cat = $cat[0];
      echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
      echo $currentBefore;
      the_title();
      echo $currentAfter;

    } 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 $currentBefore;
      the_title();
      echo $currentAfter;

    } elseif ( is_page() && !$post->post_parent ) {
      echo $currentBefore;
      the_title();
      echo $currentAfter;

    } 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 $currentBefore;
      the_title();
      echo $currentAfter;

    } elseif ( is_search() ) {
      echo $currentBefore . 'Search results for '' . get_search_query() . ''' . $currentAfter;

    } elseif ( is_tag() ) {
      echo $currentBefore . 'Posts tagged '';
      single_tag_title();
      echo ''' . $currentAfter;

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

    } elseif ( is_404() ) {
      echo $currentBefore . 'Error 404' . $currentAfter;
    }

    if ( get_query_var('paged') ) {
      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>';

  }
}

Anyway, I haven’t find a solution for parent taxonomy or post though… Still looking for a best solution for the breradcrumb. Like I always do, decrease plugin, increase loading, that’s like diet pills that work, for WordPress :P

Some handy sites

I like to spend some of my free time surfing the web for a source of idea or solution, started from Google, or Twitter, then ends at xenadrine reviews. Some are great source that I implement them into my framework without second thought.

Include JQuery

Google Libraries

If you’re working on WordPress, you can simply use this snippet:

<?php wp_enqueue_script(“jquery”); ?>

This will include a JQuery from WordPress itself. So there will no need for adding a 72kb script to load. If you’re custom built a site, use one from Google libraries will do well.

<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”?></script?>

The all-time-headache IE js

IE7 js

This plugin is quite handy. It helps make Internet Explorers to behave like a standards-compliant browser – IE7 Js

<!–[if lt IE 7]>
<script src=”http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE7.js”></script>
<![endif]–>

<!–[if lt IE 8]>
<script src=”http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE8.js”></script>
<![endif]–>

<!–[if lt IE 9]>
<script src=”http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js”></script>
<![endif]–>

Well, the bad side is, no IE6 support. You’ll have to figure this out your own again.

Get some colors inspiration

Kuler color

Kuler by Adobe. Somehow, I feel that Color Lovers did a much better job than Kuler. But nonetheless, both are where you can search for color concept.

Free stock image

sxc.hu

From time to time, I have to search for photos to be used on a project too (of course, I tried not to use stock photo is possible). Stock xChng however, is getting low and low quality. It was a good source of free stock image.

Free Icon

iconfinder.net

Icon Finder submitted by anyone. So you can be sure there are thousand if not million of icons available in all different style.

Sitcom or whatever

The Fresh Prince of Bel-Air

The Fresh Prince of Bel-Air was the first sitcom I’ve ever encounter when I was kid, then I started to watch all sort of sitcom available on TV2 on Saturday morning.

I even go extreme that I bought some season of sitcom I love watching. While I was in college, I often spend my time in my room watching those VCD and blowing some good ROMEO Y Julieta cigars. That is the only luxury time I have had when I was in college.

Malaysia Court

Recently a video in YouTube was booming and everybody sharing here and there. The Malaysia court case, I guess? Did you watch those? Or do you know what was the title of the sitcom? Cause I’m interested on purchasing them for my collection.

Hari Raya Trip

Tanjung Manis

The first time we had this trip for Hari Raya. Though I have lots of jobs, but that doesn’t really stop me from going to the visit the old-far-relative at somewhere…

Speed boat

We first arrive somewhere near Sarikei to visit uncle’s new house. The n ext mornig, we took speed boat down to Tanjung Manis. My first time arriving such a place, where 3 rows of shop houses and stated as a town too. That’s how Sarawak work huh?

Belawai

Where I visited was a town named Belawai, my mother’s hometown. Can’t help but to enjoy all those traditional houses, even though it just a few rows as well, all of them are different.

Meals

We did not spend too much time in the village, we took a few meals and went visit their ancestor for a Raya greeting.

Raya visiting

It was packed with Muslim, and yet only bunch of us Chinese looking person in there. It was interesting enough to experience this the first time. I was shocked when I saw those uncle giving coins to the children. No wonder my mother asked me to prepare coin before the visit.

Bird House

Somehow, my uncle was so into Swallow, that we took quite some times looking around the bird-houses all the way. Swallow has becoming the most worthy animal to invest this few years. You can probably notice a lot of those houses built for them, all the way from Kuching to Miri. Well, laws and rules are coming after these houses, I haven’t really see the real rules and laws, but the enforcement has been started as I know.

Talking about dare businesses

Comning back to this town, the only thing Internet is to most people are – 1, Facebook games or socialing with their cunsomer. 2, Sell product. That is good enough though. However, with all the booming of e-commerce in town, some are still lack of the “balls”

Business currencies

What I mean here is, they work like this – I buy from you, I sell to him. There will be no corporate in the process. No wholesale distributors were included in the process of making a sales. I’m not saying this is wrong with the whole process, but I have trouble with the little bit thing named “Market Pricing”.

I am no man in bussiness though. But I heard a lot of news about running businesses and I happen to have lots of friends, who are business majored.