Of course. The term dede php addfilter is very specific to the DedeCMS (织梦CMS) ecosystem. Let's break it down in detail.

What is addfilter in DedeCMS?
In DedeCMS, addfilter is a PHP function used within the list template (the template for listing articles, like list_article.htm) to dynamically generate a URL for filtering or sorting content.
The most common use case is for creating links that sort articles by a specific field, such as:
- Publish Date (发布日期)
- Click Count (点击量)
- Sticky Level (置顶级别)
- Weight/Order (权重/排序)
The function is typically used in the context of the DedeCMS tag {dede:list}.
Syntax and Parameters
The addfilter function has a specific structure. It's not a standard PHP function you call directly but rather a special tag understood by the DedeCMS engine.

Basic Syntax:
<a href="{dede:field name='phpurl'/}/plus/list.php?tid={dede:field name='id'/}&{dede:addfilter field='排序字段' type='排序方式'/}">显示文字</a>
Let's break down the {dede:addfilter} tag itself:
{dede:addfilter field='字段名' type='排序方式'/}
-
field(必需参数): Specifies the database field you want to sort by.
(图片来源网络,侵删)- Common values:
sortrank: Sort order / Weight (权重)pubdate: Publication date (发布日期)click: Click count (点击量)lastpost: Last post time (最后回复时间)mid: Author ID (作者ID)
- Common values:
-
type(必需参数): Specifies the direction of the sort.- Common values:
asc: Ascending order (升序, e.g., A-Z, 1-9, old to new)desc: Descending order (降序, e.g., Z-A, 9-1, new to old)
- Common values:
How It Works: A Practical Example
Let's imagine you have a category page (list_article.htm) and you want to add links to let users sort the articles by date (newest first) or by popularity (most clicks first).
Your list_article.htm template might look like this:
{dede:list pagesize='10'}
<li>
<a href="[field:arcurl/]">[field:title/]</a>
<span>[field:pubdate function="MyDate('Y-m-d', @me)"/] | [field:click/] clicks</span>
</li>
{/dede:list}
<!-- 分页 -->
{dede:pagelist listitem="info,index,end,pre,next,pageno" listsize="5"/}
<!-- 在分页代码下方,添加排序链接 -->
<div class="sort-links">
<strong>Sort by:</strong>
<a href="{dede:field name='phpurl'/}/plus/list.php?tid={dede:field name='id'/}&{dede:addfilter field='pubdate' type='desc'/}">Newest First</a>
<a href="{dede:field name='phpurl'/}/plus/list.php?tid={dede:field name='id'/}&{dede:addfilter field='click' type='desc'/}">Most Popular</a>
<a href="{dede:field name='phpurl'/}/plus/list.php?tid={dede:field name='id'/}&{dede:addfilter field='sortrank' type='asc'/}">Manual Order</a>
</div>
Explanation of the Example:
{dede:field name='phpurl'/}: This gets the base URL to thephpdirectory, which is wherelist.phpis located.{dede:field name='id'/}: This gets the current category ID (tid). This is crucial for ensuring the filter applies only to the articles in the current category.&{dede:addfilter field='pubdate' type='desc'/}: This is the core of the function.- When clicked, DedeCMS's
list.phpscript will see this parameter. - It will automatically generate a query string that looks like this:
?tid=123&orderby=pubdate&orderway=desc. - The
list.phpscript then uses these parameters to modify the database query, fetching articles sorted bypubdatein descending order.
- When clicked, DedeCMS's
- Resulting URLs:
- "Newest First" link might generate:
.../list.php?tid=5&orderby=pubdate&orderway=desc - "Most Popular" link might generate:
.../list.php?tid=5&orderby=click&orderway=desc
- "Newest First" link might generate:
Important Considerations and Troubleshooting
- Template Engine: Remember that this is not raw PHP. It's a template tag processed by DedeCMS's template engine. You cannot use it outside of DedeCMS template files (
.htm). {dede:list}Context: Theaddfiltertag is almost always used in conjunction with{dede:list}to provide alternative views of the same list of articles.- SEO Impact: Be aware that creating many filtered pages (e.g., sorting by every possible field) can lead to content duplication from an SEO perspective. Search engines might see
?tid=5&orderby=dateand?tid=5&orderby=clickas different pages with very similar content. Use this feature judiciously. - Not Working? If
addfilterdoesn't produce a link:- Check Typos: Ensure the
fieldandtypevalues exactly match a database column and a valid sort direction. - Check Permissions: Make sure your
list.phpfile in/plus/is executable and has the correct permissions. - Check DedeCMS Version: While this feature has been around for a long time, ensure your version of DedeCMS supports it. It's a standard feature in most versions from DedeCMS 5.6 onwards.
- Check Typos: Ensure the
Modern Alternatives
While addfilter is the "classic" DedeCMS way, modern web development often favors a more robust approach:
- AJAX Filtering: Instead of reloading the entire page, you could use JavaScript (with jQuery or Fetch API) to send the sorting parameters to the server in the background and update the article list dynamically. This provides a much better user experience.
- Custom PHP/MySQL: For more complex filtering (e.g., filtering by multiple tags, custom fields, or date ranges), you might write your own PHP controller and SQL query, giving you full control over the logic.
Summary
| Term | Meaning | Use Case |
|---|---|---|
dede |
Refers to the DedeCMS content management system. | Context for the entire question. |
php |
Indicates that the solution involves PHP code or DedeCMS's PHP-based templating. | The logic is handled by PHP files like list.php. |
addfilter |
A DedeCMS template tag that dynamically generates a URL with sorting/filtering parameters. | Creating "Sort by Date," "Sort by Popularity" links on a category page. |
In short, dede php addfilter is the DedeCMS method for creating dynamic sorting links on a list page. It's a convenient, built-in feature that leverages the system's existing list.php script to handle the database sorting logic.
