生命不息,折腾不止。文章源自狐狸影视城-https://fox-studio.net/18782.html
SEO 是网站优化,对于搜索引擎更加友好的过程。如果你不明白可以点击这里。文章源自狐狸影视城-https://fox-studio.net/18782.html
以前用的知更鸟的主题确实不错,速度快还优化好,不过现在返回不去了,很多文章是不能导入的。文章源自狐狸影视城-https://fox-studio.net/18782.html
下面是以前网站的样子。文章源自狐狸影视城-https://fox-studio.net/18782.html
文章源自狐狸影视城-https://fox-studio.net/18782.html
而且现在主题定制性较高,方便做效果。对于想我这样爱折腾的人是爱不释手的。但是弊端也很大,自从用上了这个主题,各种问题不断。从没有让我好过过,前几天刚刚怒发冲冠,把服务器系统重装,更换环境,然后删除无用的注册表,逐一导入需要的信息。文章源自狐狸影视城-https://fox-studio.net/18782.html
这两天又接着搞网站优化。唉,我是影视从业者,只是玩玩网站。文章源自狐狸影视城-https://fox-studio.net/18782.html
打开一个网页,右键→查看源代码。这些代码才是给搜索引擎看的,它们和咱们看到的东西不一样。可知道做网站一天就搞这些代码,酷毙死了。文章源自狐狸影视城-https://fox-studio.net/18782.html
其中下图中的这些标签是搜索引擎最喜欢的,也是搜索结果中显示的内容。文章源自狐狸影视城-https://fox-studio.net/18782.html
文章源自狐狸影视城-https://fox-studio.net/18782.html
之前的主题只有标题<title> 标签,描述和标签都没有。之后我加进来的。文章源自狐狸影视城-https://fox-studio.net/18782.html
我把代码放出来,其中我已经加上标注了,因为我是小白,就不详细介绍了。文章源自狐狸影视城-https://fox-studio.net/18782.html
我在修改的时候,除了百度,最有用的是 W3C 的网,也是 http 的什么创始网站啥的,反正是个网络界的第一人。不过就是用他站内搜索休要访问 google 服务器。文章源自狐狸影视城-https://fox-studio.net/18782.html
需要解释的我已经添加在代码中了文章源自狐狸影视城-https://fox-studio.net/18782.html
但是 wordpress 的页面,标签,归档等分类是没有描述和标签的。文章源自狐狸影视城-https://fox-studio.net/18782.html
你可以将以下代码加入主题 founctions.php 文件中,从而使用描述和标签功能。文章源自狐狸影视城-https://fox-studio.net/18782.html
再配合上面的代码,就可以在每个页面显示标题,标签和描述。文章源自狐狸影视城-https://fox-studio.net/18782.html
查看 SEO 代码文章源自狐狸影视城-https://fox-studio.net/18782.html
- <?php
- /* SEO 优化代码,源码自 「HotNewspro」 主题改写。
- ** 根据提示自行修改,请保留作者信息。
- */
- ?>
- <!-- 狐狸影视城 SEO 优化代码 -->
- <?php echo "n"; ?>
- <?php //开始 Title(标题) 截取。 ?>
- <?php //主页
- if ( is_home() || is_front_page()) { ?>
- <title><?php bloginfo('name'); ?> | <?php bloginfo('description'); ?></title>
- <?php } ?>
- <?php //搜索页面
- if ( is_search() ) { ?>
- <title> 搜索结果 | <?php bloginfo('name'); ?></title>
- <?php } ?>
- <?php //文章页面
- if ( is_single() ) { ?>
- <title><?php echo trim(wp_title('',0)); ?><?php if (get_query_var('page')) { echo '-第'; echo get_query_var('page'); echo '页';}?> | <?php bloginfo('name'); ?></title>
- <?php } ?>
- <?php //page 页面
- if ( is_page() && !is_front_page() ) { ?>
- <title><?php echo trim(wp_title('',0)); ?> | <?php bloginfo('name'); ?></title>
- <?php } ?>
- <?php //分类页面
- if ( is_category() ) { ?>
- <title><?php single_cat_title(); ?> | <?php bloginfo('name'); ?></title>
- <?php } ?>
- <?php //日期归档
- if ( is_month() ) { ?>
- <title><?php the_time('F'); ?> | <?php bloginfo('name'); ?></title>
- <?php } ?>
- <?php //标签
- if (function_exists('is_tag')) {
- if ( is_tag() ) { ?>
- <title><?php single_tag_title("", true); ?> | <?php bloginfo('name'); ?></title>
- <?php } ?> <?php } ?>
- <?php //作者
- if ( is_author() ) {?>
- <title><?php wp_title('');?> 发表的所有文章 | <?php bloginfo('name'); ?></title>
- <?php }?>
- <?php //结束 Title(标题) 和截取。 ?>
- <?php
- if (!function_exists('utf8Substr')) {
- function utf8Substr($str, $from, $len)
- {
- return preg_replace('#^(?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$from.'}'. '((?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$len.'}).*#s', '$1',$str); //正则表达式的搜索和替换
- } //编码声明
- }
- if ( is_single() || is_page() ){
- if ($post->post_excerpt) { //如果摘录有
- $description = str_replace("n"," ",$post->post_excerpt); //拾取文章摘录
- } else {
- //如果没有摘录,则从正文内容中截取部分作为摘录。
- if(preg_match('/<p>(.*)</p>/iU',trim(strip_tags($post->post_content)),$result)) {
- $post_content = $result['1'];
- } else {
- $post_content = str_replace("n"," ",trim(strip_tags($post->post_content)));
- }
- //如果您的网站使用了如 Visual Composer 插件。他会生成许多短代码,下面是匹配这个插件而做的删除短代码。
- if(strstr($post_content,'
- ') || strstr($post_content,'[mk') ){
- $post_content = str_replace(' ', '', $post_content);
- $post_content_r = explode("][",$post_content); //从 「][」 符号分数组
- $description = "";
- foreach ($post_content_r as $post_content ) {
- $srt1 = strcspn($post_content,"]")+"1"; //查找次一个 「]」 符号的位置
- $srt2 = Substr($post_content,$srt1); //从 $srt1 位置向后拾取字符串
- $srt3 = strcspn($srt2,"["); //从 $srt2 字符串查找第一个 「[」 位置
- $srt4 = Substr($srt2,$srt3); //从 $srt3 位置向后拾取 $srt2 字符串
- $srt5 = array($srt4=>""); //定义将拾取的 $srt4 字符串替换为空
- $srt6 = strtr($srt2,$srt5); //替换 $srt2 字符串中定义的内容 $srt4
- $description = $description . $srt6 ;
- }
- if(strlen($description)>200){$shengluehao = "...";}
- $description = utf8Substr($description,0,200).$shengluehao;
- }else{
- //如果没有使用短代码,则默认输出。
- if(strlen($description)>200){$shengluehao = "...";}
- $description = utf8Substr($post_content,0,200).$shengluehao;
- }
- }
- $keywords = "";
- $tags = wp_get_post_tags($post->ID);
- $tags = wp_get_post_tags($post->ID);
- foreach ($tags as $tag ) {
- $keywords = $keywords . $tag->name . ",";
- }
- }
- ?>
- <?php if ( is_single() ) { ?>
- <meta name="description" content="<?php echo trim($description); ?>" /><?php echo "n"; ?>
- <meta name="keywords" content="<?php echo rtrim($keywords,','); ?>" /> <?php } ?>
- <?php if ( is_page() ) { ?>
- <meta name="description" content="<?php echo trim($description); ?>" /><?php echo "n"; ?>
- <meta name="keywords" content="<?php echo rtrim($keywords,',');?>" /> <?php } ?>
- <?php if ( is_category() ) { ?>
- <meta name="description" content="<?php echo trim(strip_tags(category_description($cat_ID))); ?>" /><?php echo "n"; ?>
- <meta name="keywords" content="<?php echo trim(strip_tags(category_description($cat_ID))); ?>" />
- <?php } ?>
- <?php if ( is_tag() ) { ?>
- <meta name="description" content="<?php echo single_tag_title(); ?>" /> <?php } ?>
- <?php if ( is_home() ) { ?>
- <meta name="description" content="<?php echo get_option('swt_description'); ?>" /><?php echo "n"; ?>
- <meta name="keywords" content="<?php echo get_option('swt_keywords'); ?>" /> <?php } ?><?php echo "n"; ?>
- <!-- 狐狸影视城 SEO 优化代码 -->
- <?php echo "n"; ?>
文章源自狐狸影视城-https://fox-studio.net/18782.html
Functions.php 代码,添加分类和关键字文章源自狐狸影视城-https://fox-studio.net/18782.html
- //为 WordPress 页面添加标签和分类
- class PTCFP{
- function __construct(){
- add_action( 'init', array( $this, 'taxonomies_for_pages' ) );
- /**
- * 确保这些查询修改不会作用于管理后台,防止文章和页面混杂
- */
- if ( ! is_admin() ) {
- add_action( 'pre_get_posts', array( $this, 'category_archives' ) );
- add_action( 'pre_get_posts', array( $this, 'tags_archives' ) );
- } // ! is_admin
- } // __construct
- /**
- * 为 「页面」 添加 「标签」 和 「分类」
- *
- * @uses register_taxonomy_for_object_type
- */
- function taxonomies_for_pages() {
- register_taxonomy_for_object_type( 'post_tag', 'page' );
- register_taxonomy_for_object_type( 'category', 'page' );
- } // taxonomies_for_pages
- /**
- * 在标签存档中包含 「页面」
- */
- function tags_archives( $wp_query ) {
- if ( $wp_query->get( 'tag' ) )
- $wp_query->set( 'post_type', 'any' );
- } // tags_archives
- /**
- * 在分类存档中包含 「页面」
- */
- function category_archives( $wp_query ) {
- if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) )
- $wp_query->set( 'post_type', 'any' );
- } // category_archives
- } // PTCFP
- $ptcfp = new PTCFP();
- ?>
发个帖子,网站似乎有在闹问题。卡住了,郁闷,这是要折腾我多久啊~~~文章源自狐狸影视城-https://fox-studio.net/18782.html
seo 代码在附件下载,可以直接上传服务器,然后用 include('目录/seo.php'); 来调用。文章源自狐狸影视城-https://fox-studio.net/18782.html
2016 年 8 月 23 日 上午 6:32 2F
过来看看你的博客,希望每天都更新一些文章。
2015 年 2 月 19 日 上午 3:56 1F
你之前的没有加 title 标签么?那百度照样抓的出
2015 年 2 月 19 日 上午 9:42 B1
@ 风筝 慢