dede arclist type参数如何正确使用?

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

Of course! The dede:arclist tag is one of the most powerful and frequently used tags in DedeCMS (织梦内容管理系统). It's used to call and display lists of articles, making it essential for creating homepage news lists, article columns, and more.

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

Let's break down the type attribute in detail, as it's one of the most important for controlling what content appears in your list.


What is dede:arclist?

First, a quick overview. dede:arclist is a loop tag that retrieves a list of articles from the DedeCMS database. Its basic structure looks like this:

{dede:arclist typeid='' row='' titlelen=''}
    <a href="[field:arcurl/]">[field:title/]</a>
    <span>[field:pubdate function='MyDate("Y-m-d",@me)'/]</span>
    <p>[field:description function='cn_substr(@me, 80)'/]...</p>
{/dede:arclist}

The typeid Attribute (The "Type" You Might Be Thinking Of)

Before we dive into the type attribute, it's crucial to understand typeid, as it's often confused and is more fundamental for filtering content.

  • Purpose: typeid specifies which channel or category's articles to display.
  • Value: It accepts the ID number of a channel or category.
  • How to Find the ID:
    1. Go to your DedeCMS backend.
    2. Navigate to "核心" -> "频道模型" -> "频道管理".
    3. Hover your mouse over the channel or category you want. The ID will appear in the URL at the bottom of your browser (e.g., typeid=8).
  • Usage:
    • Single Category: typeid='8' will only show articles from the category with ID 8.
    • Multiple Categories: typeid='8,10,12' will show articles from categories 8, 10, and 12.
    • All Sub-Categories: typeid='8,0' will show articles from category 8 and all of its sub-categories. This is very useful for primary navigation.

If you don't set typeid, arclist will default to showing articles from the current channel you are on.

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

The type Attribute (The Main Focus)

The type attribute is different from typeid. It's used to filter the articles within the selected categories based on their properties or status. It accepts a comma-separated list of letters.

Here are the most common and useful values for type:

type='image' (or img)

  • Purpose: Only display articles that have a thumbnail image.
  • How it works: DedeCMS requires you to set a thumbnail for an article during or after creation. This tag filters for only those articles.
  • Common Use Case: Creating a visual news ticker or a gallery-style homepage section.

type='commend' (or iscommend, t)

  • Purpose: Only display articles that have been marked as "commended" or "featured".
  • How it works: In the article's editing page, there is a checkbox for "推荐选项" (Commend Options). Checking this box adds the article to the dede_archives table's iscommend field.
  • Common Use Case: Creating a "Featured News" or "Editor's Pick" section on your homepage.

type='hot' (or hotart, h)

  • Purpose: Only display articles that have been marked as "hot".
  • How it works: Similar to commend, there is a "hot" checkbox in the article's editing page.
  • Common Use Case: Creating a "Trending Now" or "Popular Articles" section.

type='spec' (or spec, s)

  • Purpose: Only display articles that belong to a special topic.
  • How it works: This relates to the "专题" (Special Topic) feature in DedeCMS. Articles added to a topic are marked with this flag.
  • Common Use Case: Highlighting articles that are part of a specific, temporary campaign or series.

type='top' (or top)

  • Purpose: Only display articles that are "topped" or "sticky".
  • How it works: This is for articles that you want to appear at the very top of the list, regardless of their publish date. You can set this in the article's editing page or by using the "Top Status" option.
  • Common Use Case: Creating a permanent announcement section that always appears first.

Combining typeid and type

The real power of dede:arclist comes from combining typeid and type.

Example Scenario: You want to create a "Featured Technology News" section on your homepage.

dede arclist type
(图片来源网络,侵删)
  1. You have a main "Technology" category with typeid=15.
  2. Within that category, you have several articles you've marked as "commended".

Your tag would look like this:

<h2>Featured Technology News</h2>
<ul>
    {dede:arclist typeid='15' type='commend' row='5' titlelen='40'}
        <li>
            <a href="[field:arcurl/]" title="[field:title/]">
                [field:title/]
            </a>
            <span class="date">[field:pubdate function='MyDate("m-d",@me)'/]</span>
        </li>
    {/dede:arclist}
</ul>

Explanation:

  • typeid='15': Limits the pool of articles to only those in the "Technology" category (and its sub-categories).
  • type='commend': Further filters that pool to show only the articles you've marked as "featured".
  • row='5': Limits the output to 5 articles.len='40'`: Shortens the title to a maximum of 40 characters.

Other Important arclist Attributes

While focusing on type, it's helpful to know these other key attributes:

Attribute Description Example
row The number of articles to display. row='10'
infolen The length of the article summary (in characters). infolen='120'
orderby The sorting order of the articles. Common values: pubdate (publish date), click (click count), id. orderby='click'
orderway The sort direction: desc (descending) or asc (ascending). orderway='desc'
subday Only show articles from the last N days. subday='7' (last 7 days)
channel The ID of the specific channel to pull from (overrides typeid in some contexts). channel='1'

Summary

Attribute Main Function Common Values
typeid Which category/channel to get articles from. 8, 8,10, 8,0 (ID numbers)
type What kind of articles to get from that category. image, commend, hot, top, spec (letters)

In short: Use typeid to define the source of your articles and type to define the filter for those articles. Mastering this combination is key to building dynamic and well-organized websites with DedeCMS.

-- 展开阅读全文 --
头像
C语言有类似Python matplotlib的绘图库吗?
« 上一篇 2025-12-18
dede datalist属性具体如何使用?
下一篇 » 2025-12-18

相关文章

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

目录[+]