Skip to content

Instantly share code, notes, and snippets.

@evansekeful
Last active October 3, 2017 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evansekeful/d2895e80c803f5714a9258accef3bea1 to your computer and use it in GitHub Desktop.
Save evansekeful/d2895e80c803f5714a9258accef3bea1 to your computer and use it in GitHub Desktop.
Wordpress Write Breadcrumb
/**
* http://www.bloggingtips.com/2009/02/22/create-a-breadcrumb-trail/
**/
function write_breadcrumb() {
$pid = $post->ID;
$trail = '<a href="'.get_site_url().'/">'. __('Home', 'textdomain') .'</a>';
if (is_front_page()) {
// do nothing
}
elseif (is_page()) {
$bcarray = array();
$pdata = get_post($pid);
$bcarray[] = ' &gt; '.$pdata->post_title."\n";
while ($pdata->post_parent) {
$pdata = get_post($pdata->post_parent);
$bcarray[] = ' &gt; <a href="'.get_permalink($pdata->ID).'">'.$pdata->post_title.'</a>';
}
$bcarray = array_reverse($bcarray);
foreach ($bcarray AS $listitem) {
$trail .= $listitem;
}
}
elseif (is_single()) {
$pdata = get_the_category($pid);
$adata = get_post($pid);
if(!empty($pdata)){
$data = get_category_parents($pdata[0]->cat_ID, TRUE, ' &gt; ');
$trail .= " &gt; ".substr($data,0,-5);
}
$trail.= ' &gt; '.$adata->post_title."\n";
}
elseif (is_category()) {
$pdata = get_the_category($pid);
$data = get_category_parents($pdata[0]->cat_ID, TRUE, ' &gt; ');
if(!empty($pdata)){
//return $data;
$trail .= " &gt; ".substr($data,0,-5);
}
}
$trail.="";
return $trail;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment