Of course! Let's break down titlelen in the context of DedeCMS (织梦CMS).

What is titlelen?
In DedeCMS, titlelen is a label parameter used to control the length of the title text that is displayed when using various system labels. Its name is a combination of "title" and "length".
Its primary purpose is to prevent long titles from breaking your website's layout by truncating them to a specified number of characters.
How to Use titlelen
You will use titlelen inside DedeCMS template tags (labels). The syntax is simple:
{dede:标签名 titlelen='数字'}
<a href="[field:arcurl/]">[field:title/]</a>
{/dede:标签名}
标签名: The name of the DedeCMS label you are using (e.g.,arclist,list,coolmenu).titlelen='数字': The parameter where you specify the maximum number of characters for the title. For example,titlelen='30'will show the first 30 characters of the title.
Common Examples
Here are the most common places you'll use titlelen:

In {dede:arclist} (Article List)
This is the most frequent use case. You use arclist to display a list of articles on your homepage, in a sidebar, or in other blocks.
Without titlelen:
{dede:arclist typeid='1' row='5'}
<li><a href="[field:arcurl/]">[field:title/]</a></li>
{/dede:arclist}
If an article title is "这是一个非常非常长的文章标题,可能会超出我们设定的宽度范围", it will stretch your layout.
With titlelen:

{dede:arclist typeid='1' row='5' titlelen='30'}
<li><a href="[field:arcurl/]">[field:title/]</a></li>
{/dede:arclist}
Now, any title longer than 30 characters will be automatically shortened. For example, the title above might become: "这是一个非常非常长的文章标..."
In {dede:channel} (Channel List)
When listing栏目 (channels) or their子栏目 (sub-channels), you might want to limit the displayed name length.
{dede:channel type='top' row='8' titlelen='20'}
<a href="[field:typelink/]">[field:typename/]</a>
{/dede:channel}
This will show the top 8 main channel names, but no longer than 20 characters each.
In {dede:myad} (Custom Ad)
While titlelen is for titles, it's worth noting that other labels like myad use similar parameters (e.g., textlen) for controlling ad text. The principle is the same.
Important Considerations and Best Practices
Character Counting: Chinese vs. English
A crucial point about titlelen is that it counts every character as one, regardless of whether it's a Chinese character, an English letter, or a number.
- Chinese:
你好世界(4 characters) ->titlelen='5'will show你好世界. - English:
Hello World(11 characters) ->titlelen='5'will showHello.
This is generally what you want, but be aware of it when setting your limit.
Adding Suffixes (like )
It's standard practice to add an ellipsis () to indicate that the title has been cut off. You can achieve this with a simple PHP if statement within the label.
Example with Ellipsis:
{dede:arclist typeid='1' row='5' titlelen='30'}
<li>
<a href="[field:arcurl/]">
[field:title function='(strlen(@me)>30 ? cn_substr(@me, 30)."..." : @me)'/]
</a>
</li>
{/dede:arclist}
Let's break down this function:
strlen(@me): Gets the full length of the original title.strlen(@me)>30 ? ... : ...: This is a ternary operator. It checks if the length is greater than 30.- If true: It runs
cn_substr(@me, 30)."...".cn_substris a DedeCMS function that safely cuts a string to a specified length. It appends to the end. - If false: It just displays the original title
@meas is.
- If true: It runs
SEO vs. Display
Be mindful that titlelen only affects what the user sees on your page. It does not change the actual <title> tag of the HTML page, which is critical for SEO.
- Display Title: Controlled by
titlelenin your template. Short, user-friendly. - SEO Title: Controlled by the "Title" field in the DedeCMS article backend. This should be a full, descriptive title for search engines.
The full SEO title is still used in the <title> tag of the article's own page, and in the link text that search engines index.
Summary
| Feature | Description |
|---|---|
| What it is | A DedeCMS label parameter to limit the display length of a title. |
| Purpose | To prevent layout breakage from long titles. |
| How to use | Add titlelen='N' to your DedeCMS labels (e.g., arclist, channel). |
| Key Tip | It counts every character as one (Chinese, English, etc.). |
| Best Practice | Combine it with a PHP function like cn_substr to add an ellipsis () for better user experience. |
| SEO Note | It only affects the visible title on the page, not the SEO title in the <title> tag. |
