相信很多朋友都在使用Wordpress插件WP-Postviews或者类似插件,对于大多数朋友来说,使用这样的插件仅仅需要它的点击量统计功能,其他的一切都是多余的,还等什么?自己干吧!
操作很简单,将下面的文章点击量统计代码添加到你主题的functions.php的最后一个 ?> 的前面
if ( ! function_exists( 'deel_views' ) ) :
function deel_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', 100, true);
}
}
}
}
add_action('wp_head', 'deel_record_visitors');
function deel_views($after=''){
global $post;
$post_ID = $post->ID;
$views = (int)get_post_meta($post_ID, 'views', true);
echo $views, $after;
}
endif;
调用的页面添加以下代码
本文链接:https://it72.com/798.htm