dede channel arclist如何调用指定栏目文章?

99ANYc3cd6
预计阅读时长 29 分钟
位置: 首页 DEDE建站 正文

Of course! The dede:channel and dede:arclist tags are two of the most fundamental and frequently used tags in DedeCMS (织梦内容管理系统). They work together to display lists of channel categories and the articles within them.

dede channel arclist
(图片来源网络,侵删)

Let's break them down one by one, and then show how they work together.


dede:channel 标签 (栏目/频道列表标签)

This tag is used to generate a list of your site's channels (categories or sections). It's most commonly used for creating the main navigation menu, sub-menus, or category lists.

Basic Syntax

{dede:channel type='top' row='8'}
    <a href='[field:typeurl/]'>[field:typename/]</a>
{/dede:channel}

Common Attributes

Attribute Description Example
typeid (Optional) Specify a specific channel ID to list its sub-channels. If not set, it lists channels based on type. typeid='2'
type (Optional) Defines the type of channels to list.
top: Lists only top-level channels (default).
son: Lists all sub-channels under the specified typeid.
self: Lists the channel specified by typeid and its sub-channels.
type='son'
row (Optional) The number of channels to display. row='10'
col (Optional) The number of columns to display (for creating a grid layout). col='4'
currentstyle (Optional) The HTML style for the channel that is currently being viewed. This is very useful for highlighting the active menu item. currentstyle="<li class='active'><a href='~typelink~'>~typename~</a></li>"

Available Fields (可用变量)

These are placeholders that get replaced with actual data from the database.

Field Description
[field:typename/] The name of the channel.
[field:typeurl/] The URL link to the channel's list page.
[field:id/] The ID of the channel.
[field:typelink/] An alias for [field:typeurl/].
[field:soncount/] The number of sub-channels.
[field:arccount/] The number of articles in this channel.

dede:arclist 标签 (文章列表标签)

This is the workhorse tag for displaying lists of articles. You can find it in almost any template file, especially list_article.htm, index.htm, and other list pages.

dede channel arclist
(图片来源网络,侵删)

Basic Syntax

{dede:arclist typeid='2' row='10' titlelen='30'}
    <li>
        <a href="[field:arcurl/]">[field:title/]</a>
        <span>[field:pubdate function="MyDate('Y-m-d',@me)"/]</span>
    </li>
{/dede:arclist}

Common Attributes

Attribute Description Example
typeid (Optional) The ID of the channel to get articles from. You can use multiple IDs separated by commas (e.g., typeid='1,3,5'). typeid='2'
row (Optional) The number of articles to display. row='10'
infolen (Optional) The maximum length of the article summary (description). infolen='200'
orderby (Optional) The order to sort articles by.
sortrank: Default, by manual ordering.
pubdate: By publication date.
click: By click count.
id: By article ID.
orderby='pubdate'
orderway (Optional) The sort direction.
desc: Descending (newest first, default).
asc: Ascending (oldest first).
orderway='desc'
channelid (Optional) The channel ID. Default is 1. Important when using custom model channels. channelid='1'
limit (Optional) A string to set the offset and limit, e.g., 'start,step'. limit='0,5' (show the first 5) or limit='5,5' (show articles 6-10).

Available Fields (可用变量)

Field Description
[field:title/] The article title.
[field:arcurl/] The full URL to the article's detail page.
[field:pubdate/] The publication date (timestamp format). It's best to use a function to format it.
[field:description/] The article summary (description).
[field:litpic/] The thumbnail or cover image of the article.
[field:click/] The number of clicks/views for the article.
[field:id/] The ID of the article.
[field:typedir/] The directory path of the channel the article belongs to.
[field:typename/] The name of the channel the article belongs to.

How They Work Together (组合使用)

The most common scenario is to use dede:channel to create a navigation menu, and then use dede:arclist to display the articles for the selected channel.

Example: A Standard Website Layout

Let's create a typical homepage layout with a main menu and a featured article section.

File: templets/default/index.htm

<!DOCTYPE html>
<html>
<head>{dede:global.cfg_webname/}</title>
</head>
<body>
    <!-- 1. Main Navigation Menu using dede:channel -->
    <!-- 
        - type='top': Only show top-level channels.
        - currentstyle: Highlights the active link with a class 'active'.
    -->
    <ul class="main-nav">
        {dede:channel type='top' currentstyle="<li class='active'><a href='~typelink~'>~typename~</a></li>"}
            <li><a href="[field:typelink/]">[field:typename/]</a></li>
        {/dede:channel}
    </ul>
    <hr>
    <!-- 2. Featured Article List for the first channel (ID=1) -->
    <!-- 
        - typeid='1': Get articles from channel with ID 1 (e.g., "Company News").
        - row='5': Show 5 articles.
        - orderby='pubdate': Sort by publication date.
        - orderway='desc': Newest articles first.
    -->
    <h2>Latest News</h2>
    <ul class="news-list">
        {dede:arclist typeid='1' row='5' orderby='pubdate' orderway='desc'}
            <li>
                <!-- 
                    - titlelen='50': Limit title to 50 characters.
                    - Use a function to format the date from a timestamp to a readable format.
                -->
                <a href="[field:arcurl/]">[field:title function='cn_substr(@me, 50)'/]</a>
                <span class="date">[field:pubdate function="MyDate('Y-m-d',@me)"/]</span>
            </li>
        {/dede:arclist}
    </ul>
    <hr>
    <!-- 3. Product List for another channel (ID=2) -->
    <h2>Our Products</h2>
    <div class="product-grid">
        {dede:arclist typeid='2' row='6' titlelen='30' imgwidth='150' imgheight='150'}
            <div class="product-item">
                <a href="[field:arcurl/]">
                    <img src="[field:litpic/]" alt="[field:title/]" width="150" height="150">
                    <p>[field:title/]</p>
                </a>
            </div>
        {/dede:arclist}
    </div>
</body>
</html>

Key Takeaways & Best Practices

  1. typeid is Crucial: Always specify the typeid in arclist to control which articles are displayed. If you omit it, it will pull articles from all channels, which is often not what you want.
  2. Use Functions for Dates: The pubdate field is a Unix timestamp. Always wrap it in a function like MyDate('Y-m-d', @me) to format it into a human-readable string.
  3. currentstyle is Your Friend: For navigation menus, always use currentstyle in dede:channel. It automatically applies a specific style (like a CSS class) to the link of the page the user is currently on, improving user experience.
  4. Check Your Template Files: The exact behavior can sometimes be influenced by settings in the DedeCMS backend (e.g., in "System" -> "System Basic Parameters" or "System" -> "Other Options"). Always test on your live site.
dede channel arclist
(图片来源网络,侵删)
-- 展开阅读全文 --
头像
dede runphp globals如何正确使用与配置?
« 上一篇 2025-12-02
dedecms dede arctype是什么?
下一篇 » 2025-12-02

相关文章

取消
微信二维码
支付宝二维码

目录[+]