根据mystique主题中的标题函数修改。
使用时在header.php中修改title标签内容为
<title><?php fungo_title(); ?></title>
即可。
显示形式为
博客主页显示为 博客名称 | 博客描述 |
博客文章页面为 文章标题 | 分类名 | 博客名 |
tag显示为 tag | 博客名 |
分类显示为 分类名称 | 博客名 |
$separator可以自己定义。
function fungo_title($separator = ‘ | ‘){
global $wp_query;
if (is\_front\_page() && is_home()):
$doctitle = get\_bloginfo(‘name’).$separator.get\_bloginfo(‘description’);
elseif (is\_home() || is\_singular()):
$id = $wp\_query->get\_queried\_object\_id();
$doctitle = get\_post\_meta($id, ‘title’, true);
$category = get\_the\_category();
if($category[0]->cat_name)
$doctitle = (!$doctitle && is\_front\_page()) ? get\_bloginfo(‘name’).$separator.get\_bloginfo(‘description’) : get\_post\_field(‘post\_title’, $id).$separator.$category[0]->cat\_name.$separator.get_bloginfo(‘name’);
else
$doctitle = (!$doctitle && is\_front\_page()) ? get\_bloginfo(‘name’).$separator.get\_bloginfo(‘description’) : get\_post\_field(‘post\_title’, $id).$separator.get\_bloginfo(‘name’);
elseif (is_archive()):
if (is\_category() || is\_tag() || is_tax()):
$term = $wp\_query->get\_queried_object();
$doctitle = $term->name;
elseif (is_author()):
$doctitle = get\_the\_author\_meta(‘display\_name’, get\_query\_var(‘author’));
elseif (is_date()):
if (is_day())
$doctitle = sprintf(\_\_(‘Archive for %s’, "mystique"), get\_the\_time(\_\_(‘F jS, Y’, "mystique")));
elseif (get\_query\_var(‘w’))
$doctitle = sprintf(\_\_(‘Archive for week %1$s of %2$s’, "mystique"), get\_the\_time(\_\_(‘W’, "mystique")), get\_the\_time(__(‘Y’, "mystique")));
elseif (is_month())
$doctitle = sprintf(_\_(‘Archive for %s’, "mystique"), single\_month_title(‘ ‘, false));
elseif (is_year())
$doctitle = sprintf(\_\_(‘Archive for year %s’, "mystique"), get\_the\_time(\_\_(‘Y’, "mystique")));
endif;
elseif (is_search()):
$doctitle = sprintf(_\_(‘Search results for %s’, "mystique"),’"’.esc\_attr(get\_search\_query()).’"’);
elseif (is_404()):
$doctitle = __(‘404 Not Found’, "mystique");
endif;
/\* If paged. \*/
if ((($page = $wp\_query->get(‘paged’)) || ($page = $wp\_query->get(‘page’))) && $page > 1)
$doctitle .= $separator.sprintf(__(‘Page %s’, "mystique"), $page);
/\* if comment page… \*/
if (get\_query\_var(‘cpage’))
$doctitle .= $separator.sprintf(_\_(‘Comment Page %s’, "mystique"), get\_query_var(‘cpage’));
if (!(is\_front\_page() || is\_home() || is\_singular())):
//add blog title here by fungo
$doctitle .=$separator.get_bloginfo(‘name’);
endif;
/\* Apply the wp_title filters so we’re compatible with plugins. \*/
$doctitle = apply\_filters(‘wp\_title’, $doctitle, $separator, ”);
echo $doctitle;
}