档案

Posts Tagged ‘keyword’

wordpress某段时间内的文章数

2011-07-11 留下评论

function num_posts($days=1) {//$days就是设定时间一天;
global $wpdb;
$today = gmdate(‘Y-m-d H:i:s’, time() + 3600 * 8);//获取当前的时间
$daysago = date( “Y-m-d H:i:s”, strtotime($today) – ($days * 24 * 60 * 60) );  //Today – $days
$result = $wpdb->get_results(“SELECT ID FROM $wpdb->posts WHERE post_date BETWEEN ‘$daysago’ AND ‘$today’ AND post_status=’publish’ AND post_type=’post’ ORDER BY post_date DESC “);
foreach ($result as $Item) {
$post_ID[] = $Item->ID;//已发布的文章ID,写到一个数组里面去
}
$post_num = count($post_ID);//输出数组中元素个数,文章ID的数量,也就是发表的文章数量
$output .= ‘<a>’.$post_num.'</a>’;//输出文章数量
echo $output;
}

给自己的wordpress页面及各文章添加keyword和description

2011-07-10 留下评论

这些天维护小站的时候,通过站长工具查询SEO,发现我的博客没有Keyword和Description,看着空空的就想把它加上,不懂技术、不懂代码的我玩不了php页面,只能Google学习了,通过学习成功添加,下面间方法分享给大家把:

进入wordpress后台,外观>编辑,找到并编辑当前主题的header.php页面,部分主题可能是head.php

将以下代码添加到header.php文件中(先备份下修改前的代码,以免出现问题),各主题的文件都不一样,随便找个地方放进去,最好是顶部。

<?php if (is_home()){
$description = “这里添加你的wordpress简单介绍“;
$keywords = “这里添加关键词,多个用英文逗号隔开“;
} elseif (is_single()){
$description =  substr(strip_tags($post->post_content),0,220);
$keywords = “”;
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag ) {
$keywords = $keywords . $tag->name . “, “;
}
}
?>
<meta name=”keywords” content=”<?=$keywords?>” />
<meta name=”description” content=”<?=$description?>” />

修改保存后,刷新首页看看是否添加成功,再进入某篇文章看看是否添加成功(文章页面的关键词是文章的标签、Description是一段摘要);

分类:PHP, SEO, WordPress 标签:, , , ,