Home > Article > CMS Tutorial > Discuz theme views implementation principle and solution to non-updating
Main content of this article:
Solution to the problem that the Discuz topic views do not change or change together with the number of reply posts
If you are a novice discuz developer, you can view the article from the beginning
If you are a webmaster, just read the summary at the bottom of the article
More articles are in the column: Discuz column
This page is the theme page
The red box above is the theme pageviews using $_G[forum_thread][views]
All the replies below use $_G[forum_thread][replies]
for the number of replies. However, the number of views will not increase when we refresh the page, but when the topic replies to a post, the number of views will not increase. The volume will increase
# Then let’s test it and add a new reply, and we will find that it is indeed the case! But the problem is not that simple, please continue to read below
Step one: We need to confirm the number of views and replies Is the volume of these two fields
The second step: We need to trace the principle of the increase in pageviews
Then let’s troubleshoot the first step Question: Open the database dictionary to view the pre_forum_thread table, then we will confirm that the variables we use in the source code are correct
In line 986 of the code, we have solved our first problem, which is why the data of page views and replies are the same. This is because here Made a judgment. If the number of reply posts is greater than the number of topic views, the number of views will be equal to the number of replies
Then continue to look for the code to update the topic views: at 1054# There is a viewthread_updateviews method in the ## line. According to the literal meaning, we can all understand what this method does, and the theme updates the number of views.
The steps to execute this code
addviews in the global variable
pre_forum_threadaddviews This table
addviews is greater than 100, the views of this topic will be cleared, and then the data will be stored in pre_forum_thread Views field of the topic table
preventrefresh value controls whether it is turned on or not. To optimize the number of topic views, just configure it according to Kaka.
But as a developer, the implementation of a function point must be traced back to the source code. Only in this way can we continuously improve ourselves.The above is the detailed content of Discuz theme views implementation principle and solution to non-updating. For more information, please follow other related articles on the PHP Chinese website!