Installed WordPress cos-html-cache static plug-in, generated a static file, Post-views and so on, the number of clicks plug-in is invalid,
Find some, including a JS version, need to use the Post-views plug-in, I do not want to install too many plug-ins, so the following scenario.
1:advanced Custom fields plugin.
After installation, I used to add a new field as a thumbnail field: Hits
2: Send the article,
You can fill it out or leave it blank.
3: Modify the article template file
4:
wp_conter.php file
5: Effect
corresponding See figure
?
1.
[Image]Wp-custom_fields.png
2.
[Image]Wp-article_write.png
3.
[Image]Wp-theme_js.png
4.
[Image]Wp_counter.png
5.
[Image]Wp_clicks2.png
? 6. Code [PHP] Code
<?php
/*
Plugin Name: Click to count Ajax statistics
version:1.0 Alternative Pictures
Author:zhy
Author Uri:http://blog.sina.com.cn/shengqingjingxin
*/http://www.enterdesk.com/special/linglei/?
Include_once (' wp-config.php ');
Include_once (' wp-includes/wp-db.php ');
Global $wpdb;
$postid = $_get[' id '];
if (Is_numeric ($postid)!=true) {
Exit ();
}
$strsql = "Select meta_value,post_id from $wpdb->postmeta where Meta_key = ' article_clicks ' and post_id= '. $postid;
$clicks = $wpdb->get_var ($strsql);
if ($clicks! = ") {
$clicks = $clicks +1;
$strout = $clicks;
$strsql = "UPDATE Wp_postmeta set meta_value=". $clicks. "Where Meta_key = ' article_clicks ' and post_id= '". $postid. " ";
$wpdb->query ($strsql);
} else {
$strout = "1";
$strsql = "INSERT into Wp_postmeta (post_id,meta_key,meta_value) VALUES (". $postid. ", ' article_clicks ', ' 1 ')";
$wpdb->query ($strsql);
}
echo $clicks +1;
?>
7. [Code][php] Code
Click: <span id= ' views ' ></span> times
<script>
$.get ("/wp-counter.php",
{
ID: "<?php echo get_the_id ();?>",
},
function (data,status) {
if (status = = = ' Success ') {
$ ("#views"). Text (data);
}else{
$ ("#views"). Text (<?php echo get_the_id ();?>);
}
});
</script>
Wordpress,cos-html-cache the solution of the click-count failure problem after static