Home > Article > CMS Tutorial > How to use JS to call the total number of comments in DEDECMS
How does DEDECMS use JS to call the total number of comments?
The website is being revised. The total number of comments in DEDE is static now. It would be too resource-intensive to update the HTML for each comment. Many friends on the forum have not solved it. I did some research and used it. The JS method call only queries one field. It should not waste resources. This needs to be tested. It shouldn't take up resources.
Recommended learning: 梦Weavercms
The method is as follows. It is divided into two steps.
1. Create a new fedcount.php file under PLUS with the following content
The code is as follows:
document.writeln("共有 <?php require(dirname(__FILE__)."/../include/config_base.php"); $db = new DedeSql(false); $rs = $db->GetOne("SELECT postnum FROM dede_archives WHERE ID='{$aid}'"); if(!is_array($rs)){ echo "0"; }else { echo $rs['postnum']; } ?>位网友发表了评论");
2. Insert the following code into the content page template
The code is as follows:
<script type="text/javascript" src="/plus/fedcount.php?aid={dede:field name=ID/}"></script>
Generate and you can see the effect displayed in real time.
Whether it takes up resources or not, let’s test it with friends and give feedback after using it.
If it takes up resources, then clear the contents of fedcount.php
This way, without querying the database, it will definitely not take up resources, haha.
The above is the detailed content of How to use JS to call the total number of comments in DEDECMS. For more information, please follow other related articles on the PHP Chinese website!