个人主站建立了有一段的时间了,从域名注册,空间神马的东西鼓捣完了,国内的国外的都试过了,有些对建站有效的优化方法和代码更新,做一下记录,以后更新的时候便于查询。
SEO 优化工作
主要改动:header.php
改动原因:加入meta信息(网页描述“description”和 网页关键词 "keywords")利于搜索引擎索引
代码更新:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | <?php //add by carey zhou on 2011/12/31 // add meta keywords and description by conditionary function the_excerpt_max_charlength($charlength) { $excerpt = get_the_excerpt(); $charlength++; if ( mb_strlen( $excerpt ) > $charlength ) { $subex = mb_substr( $excerpt, 0, $charlength - 5 ); $exwords = explode( ' ', $subex ); $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) ); if ( $excut < 0 ) { return mb_substr( $subex, 0, $excut ); } else { return $subex; } } else { return $excerpt; } } $description = ''; $keywords = ''; if ( is_home() || is_front_page() ) { $description = '润物无声是周润生的个人博客空间,主要用来分享和记录最新的互联网科技知识,优秀的企业架构解决方案和程序设计开发技术,同时致力于打造一个知识分享的平台。'; $keywords = 'Technology blog, Internet news, Program development, Architecture design,科技博客,互联网新闻,程序开发,架构设计'; } else if (is_single()) { $exerpt = the_excerpt_max_charlength(200); if ( $exerpt != '') { $description = $exerpt; } else { $description = $post->post_title ; } $tags = wp_get_post_tags($post->ID); foreach ($tags as $tag ) { $keywords = $tag->name . ', ' . $keywords; } $keywords = $keywords . '润物无声'; } if ( $description != '' ): ?> <meta name="description" content="<?php echo "$description" ?>" /> <?php endif; if ( $keywords != ''): ?> <meta name="keywords" content="<?php echo "$keywords" ?>" /> <?php endif; //add by carey zhou on 2011/12/31 ?> |
<?php //add by carey zhou on 2011/12/31 // add meta keywords and description by conditionary function the_excerpt_max_charlength($charlength) { $excerpt = get_the_excerpt(); $charlength++; if ( mb_strlen( $excerpt ) > $charlength ) { $subex = mb_substr( $excerpt, 0, $charlength - 5 ); $exwords = explode( ' ', $subex ); $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) ); if ( $excut < 0 ) { return mb_substr( $subex, 0, $excut ); } else { return $subex; } } else { return $excerpt; } } $description = ''; $keywords = ''; if ( is_home() || is_front_page() ) { $description = '润物无声是周润生的个人博客空间,主要用来分享和记录最新的互联网科技知识,优秀的企业架构解决方案和程序设计开发技术,同时致力于打造一个知识分享的平台。'; $keywords = 'Technology blog, Internet news, Program development, Architecture design,科技博客,互联网新闻,程序开发,架构设计'; } else if (is_single()) { $exerpt = the_excerpt_max_charlength(200); if ( $exerpt != '') { $description = $exerpt; } else { $description = $post->post_title ; } $tags = wp_get_post_tags($post->ID); foreach ($tags as $tag ) { $keywords = $tag->name . ', ' . $keywords; } $keywords = $keywords . '润物无声'; } if ( $description != '' ): ?> <meta name="description" content="<?php echo "$description" ?>" /> <?php endif; if ( $keywords != ''): ?> <meta name="keywords" content="<?php echo "$keywords" ?>" /> <?php endif; //add by carey zhou on 2011/12/31 ?>
优秀分页界面
主要改动:loop.php
改动原因:加入分页界面支持,方便浏览博文
其他工作:需要分页插件支持:http://wordpress.org/extend/plugins/wp-pagenavi
代码更新:
1 2 3 4 5 6 7 8 9 | <div class="post-nav clearfix"> <?php if(function_exists(‘wp_pagenavi’)) : ?> <?php wp_pagenavi() ?> <?php else : ?> <p id="previous"><?php previous_post_link(); ?></p> <p id="next-post"><?php next_post_link(); ?></p> <?php endif; ?> <?php do_action('graphene_post_nav'); ?> </div> |
<div class="post-nav clearfix"> <?php if(function_exists(‘wp_pagenavi’)) : ?> <?php wp_pagenavi() ?> <?php else : ?> <p id="previous"><?php previous_post_link(); ?></p> <p id="next-post"><?php next_post_link(); ?></p> <?php endif; ?> <?php do_action('graphene_post_nav'); ?> </div>
文章阅读次数支持
主要改动:loop.php
改动原因:加入文章阅读次数的跟踪,便于筛选出用户最关注的博文
其他工作:需要记录文章阅读次数的插件支持:http://wordpress.org/extend/plugins/wp-postviews
代码更新:
1 2 3 4 5 6 | <p class="post-tags"> <?php if (has_tag()) {_e('Tags:','graphene'); the_tags(' ', ', ', '');} else {_e('This post has no tag','graphene');} ?> <span> 阅读次数: <?php if(function_exists('the_views')) { the_views();} ?> </span></p> |
<p class="post-tags"> <?php if (has_tag()) {_e('Tags:','graphene'); the_tags(' ', ', ', '');} else {_e('This post has no tag','graphene');} ?> <span> 阅读次数: <?php if(function_exists('the_views')) { the_views();} ?> </span></p>
界面代码部分存在多层覆盖的现象
貌似description需要把HTML符号去掉,还需要把中文标点全部转化为英文标点。请问博主是怎么解决的?
获取文章摘要的函数get_the_excerpt()会处理html的字符,返回一个可以直接用来显示的字符串
嗯 学习了。
This site is absolutely interesting i am searching for is there the other examples? but anyway thanks a great deal as a result of I found that i used to be probing for.
i totally agree