Of course. The infolen attribute in DedeCMS (织梦CMS) is a very common and useful parameter used primarily within the {dede:list} and {dede:arclist} tags. It controls the length of the article's summary or description that is displayed on a list page.

Let's break it down in detail.
What is infolen?
infolen is a tag attribute that specifies the character length of the article's description (文章描述) to be displayed. If an article has a description filled in the backend, infolen will use that. If not, it will automatically generate a summary from the article's main body content (body).
How to Use It
The syntax is simple and is placed inside the {dede:list} or {dede:arclist} tag.
Basic Syntax:

{dede:list infolen='100'}
<a href='[field:arcurl/]'>[field:title/]</a>
<p>[field:description/]</p>
{/dede:list}
In this example:
inflen='100'tells DedeCMS to display the first 100 characters of the article's description.[field:description/]is the field that calls the description whose length is controlled byinfolen.
Detailed Explanation and Examples
The Role of infolen vs. description in the Backend
It's crucial to understand how DedeCMS prioritizes content.
-
If you fill in the "Description" field: When you edit an article in the DedeCMS backend, there is a text area specifically for "Description" (文章描述). If you put text in this field,
infolenwill use this text as its source and trim it to the specified length. -
If you leave the "Description" field empty: DedeCMS will automatically take the beginning of the article's main content (from the
bodyfield) and use that as the description for the list page, whichinfolenwill then trim.
(图片来源网络,侵删)
Practical Examples
Let's imagine you have a list page template (list_article.htm).
Example 1: Basic Usage
You want to show a 150-character summary for each article.
<h2>{dede:field.title/}</h2>
<ul class="newslist">
{dede:list infolen='150'}
<li>
<span class="title"><a href="[field:arcurl/]">[field:title/]</a></span>
<span class="info">[field:pubdate function="MyDate('Y-m-d',@me)"/]</span>
<p class="summary">[field:description/]...</p>
</li>
{/dede:list}
</ul>
Here, [field:description/] will display up to 150 characters from the article's description.
Example 2: Handling Chinese and English Characters
A common point of confusion is that infolen counts bytes, not characters**. This is important for Chinese characters, as most Chinese characters take up 2 bytes in UTF-8 encoding, while English letters take 1 byte.
- If you set
infolen='100', you will get approximately 50 Chinese characters or 100 English letters. - This can sometimes cause a Chinese character to be cut off in the middle, appearing as a garbled character ().
Best Practice: To avoid this, it's highly recommended to use a custom function to count by actual characters. You can achieve this by modifying the DedeCMS core file or, more safely, by using a custom function.
Here is a very popular and safe solution:
-
Open the file
/include/helpers/extend.helper.php. -
Add the following function to the very end of the file, just before the closing
?>:/** * 按字符数截取字符串,支持中文 * * @param $string * @param int $length * @param string $dot * @return string */ if ( ! function_exists('cn_substr')) { function cn_substr($string, $length, $dot = '...') { if (strlen($string) <= $length) { return $string; } $str = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string); $strcut = ''; if (strlen($str) > $length) { $n = $length - 1; $dot = ''; for ($i = 0; $i < $n; $i++) { $strcut .= ord($str[$i]) > 127 ? $str[$i] . $str[++$i] : $str[$i]; } $strcut = rtrim($strcut); $strcut = substr($strcut, 0, -1); $strcut .= $dot; } else { $strcut = $str; } return $strcut; } } -
Now, in your template, you can use this function to get a true character count:
{dede:list infolen='100'} <a href='[field:arcurl/]'>[field:title/]</a> <p>[field:description function="cn_substr(@me, 100)"/]</p> {/dede:list}This will now correctly cut off at 100 actual characters, whether they are Chinese or English, preventing garbled text.
Related Attributes and Best Practices
-
infolenvs.titlelen:infolencontrols the description/summary length ([field:description]).titlelencontrols the title length ([field:title]).- Example:
{dede:list titlelen='40' infolen='100'}
-
Adding "..." for Truncated Text: To make it clear that the text has been cut off, append to the end of your description.
<p>[field:description/]...</p>
Or, even better, with the custom function:
<p>[field:description function="cn_substr(@me, 100, '...')"/]</p>
-
CSS for Ellipsis (): A more modern and flexible way to handle truncation is with CSS. This avoids adding "..." to the actual content and is responsive.
.summary { width: 300px; /* Or any fixed width */ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; /* This adds the "..." automatically */ }In your HTML, you don't need to add anything:
<p class="summary">[field:description/]</p>
Summary
| Attribute | Purpose | Example |
|---|---|---|
infolen |
Controls the character length of the article's summary/description on list pages. | {dede:list infolen='100'} |
row |
Controls the number of articles to display per page. | {dede:list row='10'} |
pagesize |
Controls the number of articles per page (an alias for row). |
{dede:list pagesize='20'} |
By using infolen effectively, you can create clean, organized, and user-friendly list pages that give visitors a good preview of your article content without overwhelming them with full text.
