Of course! Let's break down dede:channel in DedeCMS, which is one of the most fundamental and commonly used tags.

What is dede:channel?
dede:channel is a DedeCMS template tag specifically designed to list the top-level channels (categories) of your website. These are the main sections you define in the DedeCMS backend under "Channels" (频道).
Its primary purpose is to create your website's main navigation menu, such as:
- Home
- News
- Products
- About Us
- Contact
Basic Syntax
The tag is typically used within a loop to list multiple channels.
{dede:channel}
<a href='[field:typelink/]'>[field:typename/]</a>
{/dede:channel}
{dede:channel}: This is the opening tag. It tells DedeCMS to start the loop for the top-level channels.{/dede:channel}: This is the closing tag, ending the loop.[field:typelink/]: This is a field variable that outputs the full URL of the channel.[field:typename/]: This is a field variable that outputs the name of the channel.
Commonly Used Parameters (Attributes)
You can add attributes to the opening tag {dede:channel} to control its behavior.

type
This is the most important parameter. It specifies which channels to list.
-
type='top'(Default): Lists only the top-level channels. This is what you use for your main navigation.{dede:channel type='top'} <li><a href="[field:typelink/]">[field:typename/]</a></li> {/dede:channel} -
type='son': Lists the direct child channels of a specified parent channel. You must use thetypeidparameter to specify the parent.<!-- Example: List child channels for the channel with ID = 2 --> {dede:channel type='son' typeid='2'} <a href="[field:typelink/]">[field:typename/]</a> {/dede:channel} -
type='self': Lists the current channel and its direct child channels. This is useful for "breadcrumb" navigation or sub-menus.
(图片来源网络,侵删)<!-- On a specific page, this will show the parent and its children --> {dede:channel type='self'} <a href="[field:typelink/]">[field:typename/]</a> {/dede:channel}
typeid
This parameter specifies the ID of the channel to be used as a reference. It's required when type='son' or type='self'.
<!-- Get children of channel ID 5 -->
{dede:channel type='son' typeid='5'}
...
{/dede:channel}
row
This parameter sets the maximum number of channels to display.
<!-- Display only the first 5 top-level channels -->
{dede:channel type='top' row='5'}
...
{/dede:channel}
currentstyle
This is a very useful parameter for styling the currently active channel link. It allows you to apply a different CSS class or style to the link that matches the page the user is currently viewing.
The syntax is currentstyle='<a href="[field:typelink/]" class="active">[field:typename/]</a>'.
<ul class="main-nav">
{dede:channel type='top' 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:
- When DedeCMS renders the list, it checks each channel.
- If the channel's ID matches the ID of the current page (article, category, etc.), it will use the code inside
currentstyleinstead of the default code (<li>...</li>in this example). - This automatically highlights the "News" link when you are on a page within the "News" category.
Field Variables ([field:xxx/])
These are placeholders that get replaced with actual data from the channel.
| Variable Name | Description | Example Output |
|---|---|---|
[field:id/] |
The unique ID number of the channel. | 1, 5, 12 |
[field:typename/] |
The name of the channel. | News, Products, About Us |
[field:typelink/] |
The full URL of the channel's main page. | https://yourdomain.com/news/ |
[field:seotitle/] |
The SEO title of the channel. | Latest News & Updates |
[field:description/] |
The description of the channel. | Read our latest news and announcements. |
[field:typedir/] |
The directory path of the channel. | /news/ |
[field:isdefault/] |
1 if it's the default channel (usually "Home"), 0 otherwise. |
0 or 1 |
Practical Examples
Example 1: Creating a Simple Main Navigation
This code creates a standard unordered list for a website's main menu.
<!-- In your header.html or main template file -->
<nav>
<ul>
{dede:channel type='top'}
<li><a href="[field:typelink/]" title="[field:typename/]">[field:typename/]</a></li>
{/dede:channel}
</ul>
</nav>
Example 2: Creating a Navigation with Active State Highlighting
This is a more advanced and common example, using currentstyle to add an "active" class.
<nav class="main-menu">
<ul>
{dede:channel type='top' currentstyle="<li class='active'><a href='[field:typelink/]'>[field:typename/]</a></li>"}
<li><a href="[field:typelink/]">[field:typename/]</a></li>
{/dede:channel}
</ul>
</nav>
With this CSS:
.main-menu ul li a.active {
color: #ff0000; /* Make the active link red */
font-weight: bold;
}
Example 3: Creating a Sub-Navigation (Dropdown Menu)
This lists the child channels of a specific parent channel (e.g., "Products").
<!-- In your template, perhaps within a Products page or a template that includes products -->
<div class="sub-nav">
<h3>Our Products</h3>
<ul>
{dede:channel type='son' typeid='3'} <!-- Assuming 'Products' has ID 3 -->
<li><a href="[field:typelink/]">[field:typename/]</a></li>
{/dede:channel}
</ul>
</div>
Summary: dede:channel vs. dede:arclist
dede:channel: Used for listing channels/categories. It's for your site's structure and navigation. It pulls data from thedede_arctypetable.dede:arclist: Used for listing articles/documents. It's for displaying content within those channels. It pulls data from thedede_archivestable.
You use dede:channel to build the menu, and you use dede:arclist on the pages that the menu links to, to show the articles for that section.
