WordPress主题制作

  1. 主页
  2. 文档
  3. WordPress主题制作
  4. header.php的处理

header.php的处理

html和head的处理如下:

<html class=”no-js” <?php language_attributes(); ?>>

<head>

<meta charset=”<?php bloginfo( ‘charset’ ); ?>“>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″ >

<link rel=”profile” href=”https://gmpg.org/xfn/11″>

<?php wp_head(); ?>

</head>
<body <?php body_class(); ?>>

原处理,仅供参考,不会用到了:

<title><?php wp_title( ‘|’, true, ‘right’ ); ?></title>

keyword处理:

function keywords(){
if( is_home() || is_front_page() ){ echo of_get_option(‘site_keywords’); }
elseif( is_category() ){ single_cat_title(); }
elseif( is_single() ){
echo trim(wp_title(,FALSE)).‘,’;
if ( has_tag() ) {foreach((get_the_tags()) as $tag ) { echo $tag->name.‘,’; } }//循环所有标签
foreach((get_the_category()) as $category) { echo $category->cat_name.‘,’; } //循环所有分类目录
}
elseif( is_search() ){ the_search_query(); }
else{ echo trim(wp_title(,FALSE)); }
}
<meta name=“keywords” content=“<?php keywords();?>”>

description处理

function description(){
if( is_home() || is_front_page() ){ echo trim(of_get_option(‘site_description’)); }
elseif( is_category() ){ $description = strip_tags(category_description());echo trim($description);}
elseif( is_single() ){
if(get_the_excerpt()){
echo get_the_excerpt();
}else{
global $post;
$description = trim( str_replace( array( \r\n, \r, \n, “ ”, ” “), ” “, str_replace( “”“, “‘”, strip_tags( $post->post_content ) ) ) );
echo mb_substr( $description, 0, 220, ‘
utf8‘ );
}
}
elseif( is_search() ){ echo ‘
‘;the_search_query();echo ‘”为您找到结果 ‘;global $wp_query;echo $wp_query->found_posts;echo ‘ 个‘; }
elseif( is_tag() ){  $description = strip_tags(tag_description());echo trim($description); }
else{ $description = strip_tags(term_description());echo trim($description); }
}
?>
<meta name=“description” content=“<?php description();?>”>

文章

这篇文章对您有用吗?

我们要如何帮助您?