dede arc.listview如何调用列表数据?

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

Of course! Let's break down dede:arc.listview in detail. This is a very common and powerful tag in DedeCMS (织梦内容管理系统) for displaying lists of articles, such as in a category archive, a search result page, or a related articles section.

dede arc.listview
(图片来源网络,侵删)

What is dede:arc.listview?

dede:arc.listview is a single-cycle (loop) tag in DedeCMS. Its primary purpose is to retrieve a list of articles (archives) from the database and display them in a specific format defined by you within the tag.

Think of it as a "for-each" loop: it fetches a set of articles and then, for each article in that set, it executes the code you've placed inside the tag.

Core Syntax and Parameters

The tag is used within a template file (.htm) and has a fixed opening and closing structure with parameters inside the opening tag.

{dede:arclist 
    flag='h' 
    typeid='2' 
    row='10' len='30' 
    orderby='pubdate' 
    orderway='desc'
}
    <!-- HTML and other Dede tags to display EACH article -->
    <li>
        <a href='[field:arcurl/]'>[field:title/]</a>
        <span>[field:pubdate function="MyDate('Y-m-d',@me)"/]</span>
    </li>
{/dede:arclist}

Key Parameters:

Parameter Description Example Value
typeid (Most Important) The ID of the category from which to fetch articles. You can specify multiple IDs separated by commas (e.g., typeid='1,3,5'). If not specified, it might pull from all categories or use a default context. typeid='2'
row The number of articles to display. row='10'
infolen The maximum length of the article's summary (description). infolen='150'
orderby The field to sort the articles by. Common values are pubdate (publication date), click (click count), id, sortrank. orderby='pubdate'
orderway The sort order. desc for descending (newest first), asc for ascending (oldest first). orderway='desc'
flag To filter articles by specific flags. h for headlines, c for recommended, p for pictures, a for bold. You can combine them (e.g., flag='hc'). flag='h'
channelid The ID of the channel. Useful if you have multiple content channels (e.g., articles, downloads, products). Default is 1 (articles). channelid='1'
subday To filter articles published within the last N days. subday='7' (last 7 days)
limit A more flexible way to set row. Format is start,row. E.g., limit='0,5' shows the first 5 articles. limit='0,10'

Available Fields (Inside the Tag)

Inside the {dede:arclist}...{/dede:arclist} block, you use [field:fieldname/] to display specific information for each article. Here are the most common fields:

dede arc.listview
(图片来源网络,侵删)
Field Name Description Example Usage
[field:title/] The article's title. <a href="[field:arcurl/]">[field:title/]</a>
[field:arcurl/] The full URL to the article's detail page. <a href="[field:arcurl/]">Read More</a>
[field:pubdate/] The publication date in Unix timestamp format. [field:pubdate function="MyDate('Y-m-d',@me)"]
[field:click/] The number of times the article has been clicked. Views: [field:click/]
[field:litpic/] The URL of the article's thumbnail or cover image. <img src="[field:litpic/]" alt="[field:title/]">
[field:description/] The article's summary (description). [field:description function="cn_substr(@me, 100)"]
[field:typelink/] A link to the article's category. <span>[field:typelink/]</span>
[field:textlink/] A pre-formatted link to the article (title + URL). [field:textlink/]
[field:info/] The full article content (can be very long). Use with caution. [field:info function="cn_substr(@me, 200)"]

Using Functions with Fields

You can use PHP functions to format the output of a field using the function attribute. This is extremely common.

<!-- Format a date: MyDate('format', timestamp) -->
[field:pubdate function="MyDate('Y-m-d H:i', @me)"]
<!-- Truncate text to a certain length: cn_substr(text, length) -->
[field:title function="cn_substr(@me, 20)"]
[field:description function="cn_substr(@me, 150)"]
<!-- Add a prefix to text -->
[field:click function="(@me + ' views')"]

Practical Examples

Example 1: Basic Category List

This is the most common use case: showing the 10 latest articles in Category ID 5.

<h2>Latest News in Category 5</h2>
<ul>
    {dede:arclist typeid='5' row='10' titlelen='40' orderby='pubdate' orderway='desc'}
        <li>
            <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>

Example 2: Featured Articles with Thumbnails

Display 5 recommended (flag='c') articles with an image and a short description.

<div class="featured-articles">
    {dede:arclist flag='c' row='5' titlelen='50' infolen='100' orderby='pubdate'}
        <article class="post">
            <a href="[field:arcurl/]" class="thumb">
                <img src="[field:litpic/]" alt="[field:title/]">
            </a>
            <h3><a href="[field:arcurl/]">[field:title/]</a></h3>
            <p class="excerpt">[field:description function="cn_substr(@me, 100)"]...</p>
        </article>
    {/dede:arclist}
</div>

Example 3: Related Articles

This is often used on the article detail page (article_article.htm). It shows articles from the same category as the current article, excluding the current article itself.

dede arc.listview
(图片来源网络,侵删)
<!-- This is typically placed in article_article.htm -->
<div class="related-articles">
    <h3>Related Articles</h3>
    {dede:arclist 
        typeid='[field:typeid/]' 
        row='5' 
        titlelen='40' 
        orderby='rand' 
        orderway='desc'
    }
        <li><a href="[field:arcurl/]">[field:title/]</a></li>
    {/dede:arclist}
</div>

Note: [field:typeid/] is a special field available in the article detail template that gets the ID of the current article's category.


Common Pitfalls and Best Practices

  1. Performance: arclist is very flexible but can be slow if used incorrectly. Avoid using it inside other loops (like loop tags) and try to be specific with your typeid and row parameters to limit the database query.
  2. Caching: DedeCMS uses a template caching system. If you make changes to an arclist tag, you might need to clear the cache (in the DedeCMS backend) or change a file's timestamp to see the changes.
  3. Typos: A single typo in a field name (e.g., [filed:title/] instead of [field:title/]) will cause that field to be completely ignored for all articles in the list.
  4. Complex Queries: For very complex list pages (e.g., with filters, pagination, and custom sorting), arclist might not be enough. In those cases, you might need to use PHP directly in the template or create a custom PHP page to handle the logic. However, for 95% of use cases, arclist is the perfect tool.
-- 展开阅读全文 --
头像
织梦DedeTemplate如何高效制作模板?
« 上一篇 2025-12-18
织梦getmembername如何获取会员名?
下一篇 » 2025-12-18

相关文章

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

目录[+]