File: /www/wwwroot/1.scey.cn/wp-content/themes/Leading/public/utils.php
<?php
function wpjam_theme_get_setting($setting_name){
return wpjam_get_setting('wpjam_theme', $setting_name);
}
// 侧边栏分类
function get_category_root_id($cat) {
$this_category = get_category($cat); // 取得当前分类
while($this_category->category_parent) // 若当前分类有上级分类时,循环
{
$this_category = get_category($this_category->category_parent); // 将当前分类设为上级分类(往上爬)
}
return $this_category->term_id; // 返回根分类的id号
}
// 面包屑导航
function get_breadcrumbs() {
global $wp_query;
if ( !is_home() ){
// Start the UL
//echo '<ul class="breadcrumb">';
echo '<i class="iconfont icon-locationfill"></i> ';
// Add the Home link
echo '<a href="'. get_option('home') .'">首页</a>';
if ( is_category() ) {
$catTitle = single_cat_title('', false);
$cat = get_cat_ID( $catTitle );
echo " <span>»</span> ". get_category_parents( $cat, TRUE, " <span>»</span> " ) ."";
}
elseif ( is_tag() ) {
echo " <span>»</span> ".single_cat_title('', false)."";
}
elseif ( is_tax() ) {
echo " <span>»</span> ".single_term_title('', false)."";
}
elseif ( is_search() ) {
echo ' <span>»</span> 搜索结果(共搜索到 ' . $wp_query->found_posts . ' 篇文章)';
}
elseif ( is_archive() ) {
echo " <span>»</span> 存档";
}
elseif ( is_404() ) {
echo " <span>»</span> 404 Not Found";
}
elseif ( is_single() ) {
$category = get_the_category();
if($category){
$category_id = get_cat_ID( $category[0]->cat_name );
echo ' <span>»</span> '. get_category_parents( $category_id, TRUE, " <span>»</span> " );
echo get_the_title();
}
}
elseif ( is_page() ) {
$post = $wp_query->get_queried_object();
if ( $post->post_parent == 0 ){
echo " <span>»</span> ".the_title('','', FALSE)."";
} else {
$title = the_title('','', FALSE);
$ancestors = array_reverse( get_post_ancestors( $post->ID ) );
array_push($ancestors, $post->ID);
foreach ( $ancestors as $ancestor ){
if( $ancestor != end($ancestors) ){
echo ' <span>»</span> <a href="'. get_permalink($ancestor) .'">'. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'</a>';
} else {
echo ' <span>»</span> '. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'';
}
}
}
}
// End the UL
//echo "</ul>";
}
}