可以用两种方式,一是插件,二是用代码
插件这个WP-Postviews关于这个插件的详细使用,下次详细说明:
seotaoke这个模板的,那就是下面的方法:
第一步,在网站的后台里找到外观编辑,这个文件functions.php,在这个文件的 ?>前面添加如下一些代码:
/* 访问计数 */
function record_visitors()
{
if (is_singular())
{
global $post;
$post_ID = $post->ID;
if($post_ID)
{
$post_views = (int)get_post_meta($post_ID, 'views', true);
if(!update_post_meta($post_ID, 'views', ($post_views+1)))
{
add_post_meta($post_ID, 'views', 1, true);
}
}
}
}
add_action('wp_head', 'record_visitors');
/// 函数名称:post_views
/// 函数作用:取得文章的阅读次数
function post_views($before = '(点击 ', $after = ' 次)', $echo = 1)
{
global $post;
$post_ID = $post->ID;
$views = (int)get_post_meta($post_ID, 'views', true);
if ($echo) echo $before, number_format($views), $after;
else return $views;
}
第二步,在你的文章里,有显示浏览次数的地方添加这样的代码:
这时到首页文章里查看即可见到效果!
第一步,在网站的后台里找到外观编辑,这个文件functions.php,在这个文件的 ?>前面添加如下一些代码:
/* 访问计数 */
function record_visitors()
{
if (is_singular())
{
global $post;
$post_ID = $post->ID;
if($post_ID)
{
$post_views = (int)get_post_meta($post_ID, 'views', true);
if(!update_post_meta($post_ID, 'views', ($post_views+1)))
{
add_post_meta($post_ID, 'views', 1, true);
}
}
}
}
add_action('wp_head', 'record_visitors');
/// 函数名称:post_views
/// 函数作用:取得文章的阅读次数
function post_views($before = '(点击 ', $after = ' 次)', $echo = 1)
{
global $post;
$post_ID = $post->ID;
$views = (int)get_post_meta($post_ID, 'views', true);
if ($echo) echo $before, number_format($views), $after;
else return $views;
}
第二步,在你的文章里,有显示浏览次数的地方添加这样的代码:
这时到首页文章里查看即可见到效果!