Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Last active August 29, 2015 14:22
Show Gist options
  • Save jrobinsonc/f93d9462ebea6be138d0 to your computer and use it in GitHub Desktop.
Save jrobinsonc/f93d9462ebea6be138d0 to your computer and use it in GitHub Desktop.
Wordpress helper: get_breadcrumbs.
<?php
/**
* get_breadcrumbs
*
* @author JoseRobinson.com
* @link https://gist.github.com/jrobinsonc/f93d9462ebea6be138d0
* @param string $home_label
* @param string $separator
* @return string
*/
function get_breadcrumbs($home_label, $separator)
{
global $post;
$output = '';
if (!is_front_page())
$output .= sprintf('<a href="%s">%s</a>', get_option('home'), $home_label);
if (is_page())
{
if (!is_front_page())
{
if($post->post_parent)
{
$anc = get_post_ancestors( $post->ID );
$anc_link = get_page_link( $post->post_parent );
$anc = array_reverse($anc);
foreach ( $anc as $ancestor )
$output .= sprintf(' %1$s <a href="%2$s">%3$s</a> ', $separator, get_permalink($ancestor), get_the_title($ancestor));
}
$output .= sprintf(' %s <span class="breadcrumb_last">%s</span>', $separator, get_the_title());
}
}
elseif (is_category() || is_single())
{
$cats = get_the_category( $post->ID );
foreach ( $cats as $cat )
{
$output .= sprintf(' %1$s <a href="%2$s">%3$s</a> ', $separator, get_category_link($cat->term_id), $cat->name);
break;
}
}
elseif (is_search())
{
$output .= sprintf(' %s <span class="breadcrumb_last">Resultados</span>', $separator);
}
// elseif (is_tag()) {$output .= single_tag_title('', false);}
// elseif (is_day()) {$output .= 'Archive: ' . get_the_time('F jS, Y');}
// elseif (is_month()) {$output .= 'Archive: ' . get_the_time('F, Y');}
// elseif (is_year()) {$output .= 'Archive: ' . get_the_time('Y');}
// elseif (is_author()) {$output .= 'Author\'s archive: ';}
// elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {$output .= 'Blog Archive: ';}
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment