dede arclist id标签具体参数如何设置?

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

Of course! The dede:arclist tag is one of the most fundamental and frequently used tags in DedeCMS (织梦CMS). Its primary purpose is to fetch and display a list of articles (archives) from the database.

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

The id parameter in dede:arclist is crucial, but it's important to understand that there are two different id parameters used in this tag, depending on whether you are calling the tag or defining its fields.

Let's break them down.


The id Parameter for Specifying Channel IDs (When Calling the Tag)

This is the most common use of the id parameter. It tells dede:arclist which channel(s) or category(s) to get articles from.

Syntax:

{dede:arclist id='channel_id1,channel_id2' ...}
    <!-- Article template content -->
{/dede:arclist}

Purpose:

  • To filter articles by their primary channel or category.
  • If you omit the id parameter, it will default to fetching articles from the current channel or category of the page you are on.

Key Details:

  • Channel ID vs. Category ID: The id parameter takes the channel ID (also known as the top-level ID of a channel), not the category ID. For example, in a default DedeCMS installation:

    dede arclist id
    (图片来源网络,侵删)
    • The "Article" channel usually has an ID of 1.
    • The "Picture" channel has an ID of 2.
    • The "Download" channel has an ID of 3.
  • How to Find a Channel ID:

    1. Log in to your DedeCMS backend.
    2. Go to [核心] -> [频道管理] (Core -> Channel Management).
    3. Hover your mouse over the channel name (e.g., "文章"). The ID will appear in the URL at the bottom of your browser, or you can often see it in the table.

    Example URL: .../dede/templets_channel_list.php?cid=1 -> The channel ID is 1.

  • Multiple Channels: You can specify multiple channels by separating their IDs with a comma.

    <!-- Get articles from both the Article channel (ID: 1) and the Download channel (ID: 3) -->
    {dede:arclist id='1,3' titlelen='30' orderby='pubdate'}
        <li>
            <a href='[field:arcurl/]'>[field:title/]</a>
            <span>[field:pubdate function="MyDate('Y-m-d',@me)"/]</span>
        </li>
    {/dede:arclist}
  • Special Value 0: Using id='0' is a special case that tells dede:arclist to fetch articles from all channels.

    dede arclist id
    (图片来源网络,侵删)
    <!-- Get articles from every single channel in the site -->
    {dede:arclist id='0' row='10'}
        ...
    {/dede:arclist}

The id Field for Displaying the Article's ID (Inside the Tag)

This is a field variable used inside the dede:arclist tag to display the unique ID of the specific article being looped through.

Syntax:

{dede:arclist ...}
    The ID of this article is: [field:id/]
{/dede:arclist}

Purpose:

  • To get the unique numeric ID of an article record in the dede_archives table.
  • This is useful for advanced development, such as:
    • Generating unique HTML element IDs (<div id="article_[field:id/]">).
    • Creating JavaScript interactions that need to reference a specific article.
    • Building complex queries or links that require the article's internal ID.

Example:

{dede:arclist id='1' row='5'}
    <div class="news-item" id="news_[field:id/]">
        <h2><a href="[field:arcurl/]">[field:title/]</a></h2>
        <p>Article Internal ID: [field:id/]</p>
        <p>Short Description: [field:description/]...</p>
    </div>
{/dede:arclist}

In this example, [field:id/] will be replaced with the actual ID of each article (e.g., 123, 124, 125, etc.).


Summary Table

Parameter/Field Syntax Location Purpose Example
id (Parameter) id='1,2' Outside the tag (in the opening tag) To specify which channel(s) to pull articles FROM. {dede:arclist id='1' row='10'...}
id (Field) [field:id/] Inside the tag (within the loop) To display the unique ID of the current article BEING looped. <span>ID: [field:id/]</span>

Complete Practical Example

Let's say you want to display the 5 most recent articles from your "Article" channel (ID: 1), and you want each list item to have a unique class based on the article's ID.

<h2>Latest News</h2>
<ul class="news-list">
    {dede:arclist id='1' row='5' titlelen='40' orderby='pubdate'}
        <li class="news-item news-item-[field:id/]">
            <a href="[field:arcurl/]" title="[field:title/]">
                [field:title/]
            </a>
            <span class="date">[field:pubdate function="MyDate('Y-m-d',@me)"/]</span>
        </li>
    {/dede:arclist}
</ul>

HTML Output:

<h2>Latest News</h2>
<ul class="news-list">
    <li class="news-item news-item-152">
        <a href="/article/152.html" title="DedeCMS教程发布啦!">
            DedeCMS教程发布啦!
        </a>
        <span class="date">2025-10-27</span>
    </li>
    <li class="news-item news-item-151">
        <a href="/article/151.html" title="网站维护通知">
            网站维护通知
        </a>
        <span class="date">2025-10-26</span>
    </li>
    ...
</ul>
-- 展开阅读全文 --
头像
dede arclist 如何修改?
« 上一篇 01-09
织梦数据库密码忘了怎么改?
下一篇 » 01-09

相关文章

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

目录[+]