標籤:des blog http os io ar 檔案 art div
裝了wordpress cos-html-cache 靜態外掛程式後,產生了靜態檔案,post-views等點擊數外掛程式就失效了,
找了一些,包括有個js版本的,需要用到post-views外掛程式,我也不想裝太多外掛程式,於是有了下面的方案。
1:Advanced Custom Fields外掛程式。
安裝後,我原先用作縮圖欄位的,新增加一個欄位:點擊數
2:發文章,
可以隨便填寫,也可以不填
3:修改文章模板檔案
4:
wp_conter.php檔案
5:效果
對應見圖
?
1. [圖片] wp-custom_fields.png 2. [圖片] wp-article_write.png 3. [圖片] wp-theme_js.png 4. [圖片] wp_counter.png 5. [圖片] wp_clicks2.png
?6. [代碼][PHP]代碼
<?php
/*
Plugin Name: 點擊數ajax統計
Version: 1.0另類圖片
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. [代碼][PHP]代碼
點擊: <span id=‘views‘></span> 次
<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靜態化後,點擊數失效問題的解決方案