Of course. Let's break down dede.totalresult, a very important and frequently used variable in the DedeCMS (织梦CMS) templating system.

What is dede.totalresult?
In simple terms, dede.totalresult is a DedeCMS global variable that holds the total number of records (results) found by the current query.
It is most commonly used within list templates (those in the /templets/default/ directory, like list_article.htm) to display the total number of articles or items in a category, search result, or other list-based page.
How It Works: The Context
dede.totalresult is not just a random number. It is generated by the PHP backend when a page is requested. Here's the typical flow:
- A user visits a category page (e.g.,
http://your-site.com/plus/list.php?tid=5). - DedeCMS's PHP code queries the database to get all articles belonging to category ID
5. - The query also calculates the
COUNT(*)of these articles. - This total count is stored in the global variable
$totalresultin the PHP code. - DedeCMS then parses the list template (
list_article.htm). During parsing, it exposes this PHP variable to the template engine through theglobal $totalresult;declaration. - In the template, you access it using the syntax
{dede:global name='totalresult'/}.
How to Use It in Your Templates
The standard way to use dede.totalresult is within the {dede:global} tag.

Basic Usage
This will simply output the total number as a plain integer.
<p>共有文章:{dede:global name='totalresult'/} 篇</p>
Example Output:
共有文章:128 篇
Practical Example: A Complete Pagination Block
dede.totalresult is most powerful when used with pagination. It gives the user context about the size of the result set they are browsing.
Here is a common and well-structured pagination block you would find in a list_article.htm template.

<div class="dede_pages">
<ul class="pagelist">
<!-- "Total Items" Info -->
<li><span class="pageinfo">共 <strong>{dede:global name='totalresult'/}</strong> 条记录</span></li>
<!-- "Previous Page" Link -->
{dede:prepage/}
<!-- Page Number Links -->
{dede:pagelist listsize='5' listitem='info,index,end,pre,next,pageno'/}
<!-- "Next Page" Link -->
{dede:nextpage/}
</ul>
</div>
Explanation of the example:
<li><span>...: This line usesdede.totalresultto display the total number of records, which is great for user experience.{dede:prepage/}: Generates a link to the previous page of results.{dede:pagelist listsize='5' listitem='...'}: This is the core pagination tag.listitem='...': Specifies which parts of the pagination to display.infois the part that shows "Total X records, Y pages", which often usestotalresultinternally.listsize='5': Shows 5 page numbers before and after the current page.
{dede:nextpage/}: Generates a link to the next page of results.
Key Points and Troubleshooting
-
Scope:
dede.totalresultis only available on list-type pages. You will not find a value for it on single-article pages (likearticle_article.htm) or the homepage. Trying to use it there will result in empty output or an error. -
When it might be empty: If the query returns no results (e.g., an empty category or a search with no matches),
dede.totalresultwill be0. -
Custom SQL Queries: If you are using a custom query in your PHP code (e.g., in a custom PHP page or a plugin), you must manually set the
$totalresultvariable for it to be available in the template.// In your custom PHP file $query = "SELECT * FROM `#@__archives` WHERE typeid = 10"; $dsql->SetQuery($query); $dsql->Execute(); $totalresult = $dsql->GetTotalRow(); // This is the key line global $totalresult; // Then include and parse your template include(DEDETEMPLATE.'/custom_list.htm');
-
Caching: Be aware that DedeCMS uses extensive caching. If you modify a template file, you may need to clear the cache (in the DedeCMS backend -> System -> Cache Settings) or rename the
cachedirectory temporarily to see your changes take effect.
Summary
| Feature | Description |
|---|---|
| What it is | A DedeCMS template variable that holds the total count of records for the current list page. |
| Syntax | {dede:global name='totalresult'/} |
| Primary Use Case | Displaying the total number of articles in a category, search results, etc., especially in pagination. |
| Location | Primarily used in list templates (e.g., list_article.htm). |
| Availability | Not available on single-article or static pages. Its value depends on the backend database query count. |
By understanding dede.totalresult, you can create more informative and user-friendly list pages for your DedeCMS website.
