zblog如何統(tǒng)計及顯示瀏覽次數(shù)
2024-07-09 22:57:57
供稿:網(wǎng)友
有的zblog模板默認(rèn)沒有統(tǒng)計、顯示文章瀏覽次數(shù)。若想添加,請看:
1.更新瀏覽計數(shù)
在打開單頁日志后產(chǎn)生,每刷新一次,計數(shù)加1。
在b_article-single.html模板中,你認(rèn)為合適的位置加入以下代碼
<span id="spn<#article/id#>"></span>
<script type="text/javascript">strBatchCount+="spn<#article/id#>=<#article/id#>,"</script>
注:<span>標(biāo)簽內(nèi)顯示的就是當(dāng)前文章的瀏覽次數(shù)。
2.顯示瀏覽計數(shù)
只適用在列表頁,如首頁和分類頁。動態(tài)加載,不隨當(dāng)前頁刷新累加。
需要修改b_article-multi.html模板,在你認(rèn)為合適的位置加入以下代碼。
<span id="spn<#article/id#>"></span>
<script type="text/javascript">strBatchView+="spn<#article/id#>=<#article/id#>,"</script>
注:也可以用<#article/viewnums#>標(biāo)簽,但它只能在索引重建后更新數(shù)值。
3.必需輔助代碼(默認(rèn)模板已經(jīng)包含這些代碼)
在TEMPLATE/ default.html,single.html,catalog.html 等頁面的頭部和尾部(指<body ></ body>內(nèi))都要有如下代碼計數(shù)器才能正常工作。
TEMPLATE/default.html,single.html,catalog.html頭部代碼
<script type="text/javascript">
var strBatchView="";
var strBatchInculde="";
var strBatchCount="";
</script>
TEMPLATE/default.html,single.html,catalog.html尾部代碼
<script type="text/javascript">
$(document).ready(function(){
try{
var elScript = document.createElement("script");
elScript.setAttribute("language", "JavaScript");
elScript.setAttribute("src", "<#ZC_BLOG_HOST#>function/c_html_js.asp?act=batch"+unescape("%26")+"view=" + escape(strBatchView)+unescape("%26")+"inculde=" + escape(strBatchInculde)+unescape("%26")+"count=" + escape(strBatchCount));
document.getElementsByTagName("body")[0].appendChild(elScript);
}
catch(e){};
});
</script>