dede arclist index标签如何正确调用?

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

Of course! Let's break down the dede:arclist tag, which is one of the most fundamental and frequently used tags in DedeCMS (织梦内容管理系统). The term "index" in this context usually refers to using the tag on your website's homepage to display a list of articles.

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

Here’s a comprehensive guide covering its purpose, common attributes, usage examples, and best practices.


What is dede:arclist?

The dede:arclist tag is used to fetch and display a list of articles from the DedeCMS database. It's extremely versatile and can be configured to pull articles from specific channels, with specific conditions, and display them in various formats.

Think of it as your primary tool for creating:

  • Homepage article lists
  • Latest news widgets
  • Article lists in specific columns
  • Related article suggestions
  • Any other place where you need a list of articles.

Basic Syntax

The dede:arclist tag is used within a template file (.htm) and has a simple structure:

dede arclist index
(图片来源网络,侵删)
{dede:arclist}
    <a href='[field:arcurl/]'>[field:title/]</a>
    <span>[field:pubdate function="MyDate('@me', 'Y-m-d')"/]</span>
{/dede:arclist}
  • {dede:arclist}: The opening tag. All attributes go here.
  • The HTML and other DedeCMS tags ([field:xxx/]) that define how each article in the list is displayed.
  • {/dede:arclist}: The closing tag.

Key Attributes for Homepage/General Use

Attributes are added to the opening tag to control which articles are fetched and how they are ordered. Here are the most important ones for a typical homepage index list.

A. Controlling Which Articles to Get

Attribute Description Common Value(s)
typeid (Most Important) Specifies the ID(s) of the channel(s) to get articles from. 1 (Single channel)
1,2,3 (Multiple channels, comma-separated)
top (All top-level channels)
row The number of articles to display. 10 (Show 10 articles)
limit A more flexible way to set the number and starting point. Format: start,num. 0,10 (Show 10 articles, starting from the first one)
10,5 (Skip the first 10, show the next 5)
flag Filters articles by special status flags. h (headline/featured)
c (recommended)
p (picture)
a (bold)
Multiple flags can be combined, e.g.,hc(headline and recommended).
channelid The ID of the specific channel model. Useful if you have custom article types. 1 (Default article channel)

B. Controlling the Order of Articles

Attribute Description Common Value(s)
orderby The field to sort the articles by. pubdate (Publish date, default)
id (Article ID)
click (Click count)
arcrank (Comprehensive sorting)
orderway The sort order. desc (Descending, e.g., newest first, highest clicks first - default)
asc (Ascending, e.g., oldest first)

The Most Common Use Case: Homepage Article List

Let's create a typical homepage layout with a featured section and a latest news section.

Scenario:

  • Featured Section: Show 3 featured articles (flag='h') from the "Technology" channel (ID=1).
  • Latest News Section: Show 10 latest articles from the "News" channel (ID=2).

Template Code (index.htm)

<!DOCTYPE html>
<html>
<head>My DedeCMS Website</title>
</head>
<body>
    <!-- 1. Featured Article Section -->
    <div class="featured-section">
        <h2>Featured Stories</h2>
        {dede:arclist typeid='1' row='3' flag='h' orderby='pubdate' orderway='desc'}
            <div class="featured-item">
                <!-- You might want to show an image here -->
                <!-- <img src="[field:litpic/]" alt="[field:title/]"> -->
                <a href="[field:arcurl/]" title="[field:title/]">[field:title/]</a>
                <p class="summary">[field:description function='cn_substr(@me, 100)'/]...</p>
            </div>
        {/dede:arclist}
    </div>
    <hr>
    <!-- 2. Latest News Section -->
    <div class="news-section">
        <h2>Latest News</h2>
        <ul>
            {dede:arclist typeid='2' row='10' limit='0,10' orderby='pubdate' orderway='desc'}
                <li>
                    <a href="[field:arcurl/]" title="[field:title/]">[field:title/]</a>
                    <span class="date">[field:pubdate function="MyDate('@me', 'Y-m-d')"/]</span>
                </li>
            {/dede:arclist}
        </ul>
    </div>
</body>
</html>

Important Field Variables ([field:xxx/])

Inside the arclist loop, you use [field:xxx/] to display specific information for each article.

Variable Description
[field:title/] The article's title.
[field:arcurl/] The full URL to the article's page.
[field:litpic/] The URL of the article's thumbnail or cover image.
[field:description/] The article's description/summary.
[field:pubdate/] The publication date (Unix timestamp format). You almost always need to apply a function to format it.
[field:click/] The number of clicks/views the article has received.
[field:id/] The unique ID of the article.
[field:typename/] The name of the channel the article belongs to.

Date Formatting Function

You must format the pubdate field to make it readable. Use the function attribute with MyDate.

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

Syntax: [field:pubdate function="MyDate('@me', 'format-string')/"]

  • @me: This is a placeholder for the raw value of the field (the Unix timestamp).
  • format-string: The desired output format (similar to PHP's date() function).

Examples:

  • [field:pubdate function="MyDate('@me', 'Y-m-d')/"] -> 2025-10-27
  • [field:pubdate function="MyDate('@me', 'Y-m-d H:i')/"] -> 2025-10-27 15:30
  • [field:pubdate function="MyDate('@me', 'Y年m月d日')/"] -> 2025年10月27日

Advanced Tips & Best Practices

  1. Use limit instead of row for pagination: When you have a "more" link to an archive page, use limit in your main list (e.g., limit='0,10') and then pass the pageno variable in the URL to the target archive page.

  2. Performance: Avoid using arclist without a typeid on a page with many articles, as it will query all channels, which can be slow. Always specify typeid when possible.

  3. Caching: DedeCMS has a built-in caching mechanism. The arclist tag results are cached, which improves page load speed. You can adjust cache settings in the DedeCMS backend.

  4. Using innertext: You can wrap your HTML in the opening tag itself, which can sometimes be cleaner.

    Example:

    {dede:arclist typeid='1' row='5' titlelen='30'}
        <li><a href="[field:arcurl/]">[field:title/]</a></li>
    {/dede:arclist}

    is the same as:

    {dede:arclist typeid='1' row='5' titlelen='30'}
        <li>
            <a href="[field:arcurl/]">[field:title/]</a>
        </li>
    {/dede:arclist}

By mastering dede:arclist, you can build dynamic and content-rich websites with DedeCMS very effectively. Start with the basic attributes and gradually explore more advanced options as you need them.

-- 展开阅读全文 --
头像
C语言for循环中continue如何跳转到循环条件判断?
« 上一篇 12-12
织梦如何去掉首页index.html后缀?
下一篇 » 12-12

相关文章

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

目录[+]