// Breadcrumb for the top of pages
function cp_breadcrumb() {
global $app_abbr, $post;
$delimiter = '»';
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
if ( !is_home() || !is_front_page() || is_paged() ) :
$flag = 1;
echo '<div id="crumbs">';
echo '<a href="' . get_bloginfo('url') . '">' . __('Home', 'appthemes') . '</a> ' . $delimiter . ' ';
// figure out what to display
switch ($flag) :
case is_tax(APP_TAX_TAG):
echo $currentBefore . __('Ads tagged with', 'appthemes') .' '' . single_tag_title('', false) . ''' . $currentAfter;
break;
case is_tax():
// get the current ad category
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
// get the current ad category parent id
$parent = $term->parent;
// WP doesn't have a function to grab the top-level term id so we need to
// climb up the tree and create a list of all the ad cat parents
while ($parent):
$parents[] = $parent;
$new_parent = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
$parent = $new_parent->parent;
endwhile;
// if parents are found display them
if(!empty($parents)):
// flip the array over so we can print out descending
$parents = array_reverse($parents);
// for each parent, create a breadcrumb item
foreach ($parents as $parent):
$item = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
$url = get_term_link( $item->slug, APP_TAX_CAT );
echo '<a href="'.$url.'">'.$item->name.'</a> ' . $delimiter . ' ';
endforeach;
endif;
echo $currentBefore . $term->name . $currentAfter;
break;
case is_singular(APP_POST_TYPE):
// get the ad category array
$term = wp_get_object_terms($post->ID, APP_TAX_CAT);
if(!empty($term)):
// get the first ad category parent id
$parent = $term[0]->parent;
// get the first ad category id and put into array
$parents[] = $term[0]->term_id;
// WP doesn't have a function to grab the top-level term id so we need to
// climb up the tree and create a list of all the ad cat parents
while ($parent):
$parents[] = $parent;
$new_parent = get_term_by( 'id', $parent, APP_TAX_CAT );
$parent = $new_parent->parent;
endwhile;
// if parents are found display them
if(!empty($parents)):
// flip the array over so we can print out descending
$parents = array_reverse($parents);
// for each parent, create a breadcrumb item
foreach ($parents as $parent):
$item = get_term_by( 'id', $parent, APP_TAX_CAT );
$url = get_term_link( $item->slug, APP_TAX_CAT );
echo '<a href="'.$url.'">'.$item->name.'</a> ' . $delimiter . ' ';
endforeach;
endif;
endif;
echo $currentBefore . the_title() . $currentAfter;
break;
case is_single():
$cat = get_the_category();
$cat = $cat[0];
echo get_category_parents($cat, TRUE, " $delimiter ");
echo $currentBefore . the_title() . $currentAfter;
break;
case 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 . single_cat_title() . $currentAfter;
break;
case is_page():
// get the parent page id
$parent_id = $post->post_parent;
$breadcrumbs = array();
if ($parent_id > 0 ) :
// now loop through and put all parent pages found above current one in 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 . ' ';
endif;
echo $currentBefore . the_title() . $currentAfter;
break;
case is_search():
echo $currentBefore . __('Search results for', 'appthemes') .' '' . get_search_query() . ''' . $currentAfter;
break;
case is_tag():
echo $currentBefore . __('Posts tagged with', 'appthemes') .' '' . single_tag_title('', false) . ''' . $currentAfter;
break;
case is_author():
global $author;
$userdata = get_userdata($author);
echo $currentBefore . __('About', 'appthemes') .' ' . $userdata->display_name . $currentAfter;
break;
case 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;
break;
case 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;
break;
case is_year():
echo $currentBefore . get_the_time('Y') . $currentAfter;
break;
case is_archive():
if( !empty($_GET['sort']) && $_GET['sort'] == 'random' )
echo $currentBefore . __('Random Ads', 'appthemes') . $currentAfter;
elseif( !empty($_GET['sort']) && $_GET['sort'] == 'popular' )
echo $currentBefore . __('Popular Ads', 'appthemes') . $currentAfter;
else
echo $currentBefore . __('Latest Ads', 'appthemes') . $currentAfter;
break;
case is_404():
echo $currentBefore . __('Page not found', 'appthemes') . $currentAfter;
break;
endswitch;
if ( get_query_var('paged') ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() || is_archive() || is_tax() ) echo ' (';
echo __('Page', 'appthemes') . ' ' . get_query_var('paged');
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() || is_archive() || is_tax() ) echo ')';
}
echo '</div>';
endif;
}
There are currently 1 users browsing this thread. (0 members and 1 guests)