wordpress,cos-html-cache靜態化後,點擊數失效問題的解決方案

來源:互聯網
上載者:User

標籤: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]代碼     

點擊:&nbsp;<span id=‘views‘></span>&nbsp;次
<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靜態化後,點擊數失效問題的解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.