Of course. dede:channel is one of the most fundamental and frequently used tags in the DedeCMS (织梦CMS) template engine. It's used to retrieve and display channel (category) information from the database.

Here’s a comprehensive guide covering its purpose, syntax, attributes, and practical examples.
What is dede:channel?
The dede:channel tag is specifically designed to fetch a list of channels (also known as categories, sections, or栏目 in Chinese). These channels are defined in the DedeCMS backend under "频道管理" (Channel Management).
Its primary uses are:
- Creating a main navigation menu.
- Building a sidebar category list.
- Displaying a breadcrumb trail (though
dede:positionis more common for this). - Generating a list of parent categories for sub-categories to be listed under.
Basic Syntax
The dede:channel tag is always used within a loop structure. The most common way to use it is with the typeid attribute to specify which parent channel's children you want to display.

{dede:channel typeid='0' row='8'}
<a href="[field:typelink/]">[field:typename/]</a>
{/dede:channel}
Key Attributes
Attributes control which data is retrieved and how it's formatted.
typeid (Most Important)
- Purpose: Specifies the ID of the parent channel. The tag will list all direct children of this channel.
- Value: A channel's ID number.
- Special Values:
typeid='0': Lists all top-level (primary) channels.typeid='-1': Lists all channels, including sub-channels, in a nested structure.'self': Lists only the current channel itself (useful for getting info about the page you're on).
row
- Purpose: Sets the maximum number of channels to display.
- Value: An integer (e.g.,
row='10'will show a maximum of 10 channels).
col
- Purpose: This is the attribute you asked about. It specifies the number of columns to display the results in. DedeCMS will automatically calculate the column width based on the
rowandcolvalues. - Value: An integer (e.g.,
col='4'will display the channels in a 4-column layout).
type
- Purpose: Specifies the type of channels to retrieve.
- Value:
top: (Default) Only top-level channels.sun: Only sub-channels.self: Only the channel specified bytypeid.
currentstyle
- Purpose: Extremely useful for navigation menus. It allows you to apply a specific CSS style to the link of the channel that is currently being viewed.
- Value: A string of HTML and CSS.
- Syntax:
currentstyle='<li class="active"><a href="[field:typelink/]">[field:typename/]</a></li>'- If the current page is within this channel, the link will be wrapped with the
<li class="active">...</li>tags. Otherwise, it will use the default format.
- If the current page is within this channel, the link will be wrapped with the
noself
- Purpose: When used with
typeid='self', this prevents the channel from linking to itself. It will just display the channel name as plain text.
Available Fields (Placeholders)
Inside the {dede:channel}...{/dede:channel} loop, you can use these placeholders to display specific information for each channel.
| Field Name | Description |
|---|---|
[field:id/] |
The unique ID of the channel. |
[field:typename/] |
The name of the channel (e.g., "Company News", "Products"). |
[field:typelink/] |
The full URL link to the channel's archive list page. This is the most common field for links. |
[field:typedir/] |
The directory path of the channel (e.g., /a/gongsi/). Useful for images. |
[field:seotitle/] |
The SEO title of the channel. |
[field:description/] |
The description of the channel. |
[field:ismenu/] |
1 if the channel is displayed in the menu, 0 otherwise. |
Practical Examples
Example 1: Basic Main Navigation Menu
This code lists all top-level channels and highlights the active one.
<ul id="mainNav">
{dede:channel typeid='0' currentstyle="<li class='active'><a href='[field:typelink/]'>[field:typename/]</a></li>"}
<li><a href="[field:typelink/]">[field:typename/]</a></li>
{/dede:channel}
</ul>
How it works:
typeid='0'gets all main channels.currentstyleis the key. If you are on the "Products" page, the<li>for "Products" will automatically get theclass="active"attribute.
Example 2: Sidebar Category List with Columns
This code displays the sub-channels of the channel with ID 2 in a 2-column layout.
<div class="sidebar-categories">
<h3>Product Categories</h3>
<div class="category-list">
{dede:channel typeid='2' row='10' col='2'}
<div class="category-item">
<a href="[field:typelink/]">[field:typename/]</a>
</div>
{/dede:channel}
</div>
</div>
How it works:
typeid='2'targets the channel with ID 2 (e.g., "Products").row='10'says "get up to 10 sub-channels".col='2'says "display them in 2 columns". DedeCMS will automatically create the necessary HTML structure (often using<dl>,<dt>,<dd>or<div>floats) to achieve this.
Example 3: Getting Info for the Current Channel
Sometimes you need the name or description of the current channel, not a list of its children.
<h1>[field:typename/]</h1> <p>[field:description function='htmlspecialchars(@me)'/]</p>
How it works:
- This code would typically be placed on a category list page (e.g.,
plus/list.php?tid=5). - By using
typeid='self'(which is the default behavior if notypeidis specified on a category page), the tag doesn't loop. Instead, it just outputs the single channel's information once. function='htmlspecialchars(@me)'is a safety measure to prevent XSS attacks by converting special characters to HTML entities.
Troubleshooting Common Issues
-
Problem: The
colattribute isn't working as expected.- Solution: The
colattribute relies on the default CSS output of DedeCMS. If your theme heavily customizes the output, you might need to adjust your CSS or manually structure the HTML with nested loops to achieve the desired column layout. Thecolattribute is a shortcut, not a magic bullet.
- Solution: The
-
Problem: Links are broken or go to the wrong page.
- Solution: Double-check that you are using
[field:typelink/]for links to category archive pages. Use[field:typedir/]for paths to images or other resources. Ensure your channel settings in the DedeCMS backend are correct (e.g., "File naming rule").
- Solution: Double-check that you are using
-
Problem: No channels are showing up.
- Solution:
- Check that you have channels created in the backend.
- Verify the
typeidvalue is correct. You can find a channel's ID by hovering over its edit link in the backend. - Ensure the channels are set to "显示" (Visible) and are of a type that can be listed (e.g., not an external link).
- Solution:
