I’m sure this tutorial has been done a hundred-times over, but I blog so I don’t have to remember. This function will help you eliminate a bloated, self-serving plug-in like Yoast Breadcrap; by using the ever popular (and super useful) conditional tags…
Step 1: Open custom_functions.php and paste the following code at the bottom:
// Build Breadcrumbs
function the_crumbs() {
if (!is_home()) {
echo '<a href="';
echo get_option('home');
echo '">';
echo 'Home'; // Home Link Text, change this to meet your needs
echo "</a> >> ";
if (is_category() || is_single()) {
the_category(', ','&title_li=');
if (is_single()) {
echo " >> ";
the_title();
}
} elseif (is_page()) {
echo the_title();
}}}
// Show Breadcrumbs
function show_crumbs() { ?>
<div id="crumbs">
<?php the_crumbs(); ?>
</div>
<?php }
add_action('thesis_hook_before_content','show_crumbs');
Step 2: Open custom.css and paste the following:
/* Breadcrumbs */
#crumbs {
font-size: 11px; /*font size, change this to whatever you want*/
padding: 10px 0px 0px 10px; /*10 padding top, 10 padding left*/
}
#crumbs a {
color: #00F /*change this to whatever color you want*/
}
#crumbs a:hover {
text-decoration: underline; /*underline the links on a mouse over*/
}
UPDATE 6.29.10 Thank you Chris for the tip on multiple categories. I have updated the code above with your fix!
Related posts:
{ 13 comments… read them below or add one }
Thanks for sharing. I already use your code in my website . it help me solve the multi category problem. Thanks you.
Hey Greg,
Very neat code. Thanks for sharing.
Thanks for the tip. How can I make the breadcrumbs inherit the fonts and body colors that I chose in Design Options?
Nice one Greg for the snippet, I’m currently creating a ‘cheat-sheet’ of my commonly used hooks to save time and this will be added to the mix. Also props to Chris for the multiple category fix, I’ve run into that problem before!
Rockin’ awesome. Glad it’s helping people!
@james – I added the following lines to get pages and subpages. I think it only works for 1 subpage level (as that’s all I need)… but should be easy to set for another.
take out
elseif (is_page()) {
echo the_title();
}}}
and add in the following….
if ( is_page() && $post->post_parent ) {
echo ‘post_parent) . ‘ “> ‘;
echo get_the_title($post->post_parent) . ” “;
echo ” >> “;
} if ( is_page() ) {
echo the_title();
}
}
}
I tried to get 2 plugins to work with thesis and hooks but couldn’t get it. This took less than 30 seconds and works great. A few customization things with the CSS and I’m set. Thanks a ton!
Very nice, I have check the code.. works great!
Thanks for this tutorial, it has really helped me out.
I liked the plugin that could do this, but I always do my best to get things displaying without using plugins and this just worked perfectly.
@Greg- Nice snippet there mate…
@Chris- Thanks for adding on to it…
It works, but how to show posts & page parents?
Thanks for posting this. I had an issue with it when a post was assigned to multiple categories, but it’s an easy fix:
the_category('title_li=');should be changed tothe_category(', ','&title_li=');. Without this adjustment, your code will displaytitle_liin front of each additional category the post is assigned to.I didn’t notice that at the beginning, but then I had the same problem so.. thank you so much for posting this Chris!
{ 6 trackbacks }