dede arclist body标签如何调用文章内容?

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

Of course! The arclist tag is one of the most fundamental and frequently used tags in DedeCMS (织梦内容管理系统). Its body attribute is a powerful tool for displaying custom summaries or introductions for your articles.

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

Let's break down everything you need to know about the dede:arclist tag and its body attribute.


What is the dede:arclist tag?

The arclist tag is used to fetch and display a list of articles from the DedeCMS database. It's extremely versatile and can be used to create:

  • Homepage article lists
  • Latest news sections
  • Related article lists
  • Article indexes by category
  • And much more

The body Attribute Explained

The body attribute's primary function is to display the content of the article's body field, but with a crucial limitation: it automatically truncates the text to a specified length.

This is its main difference from the description (info) attribute.

dede arclist body
(图片来源网络,侵删)
  • description / info: Displays the value from the article's "description" ( field in the后台 (backend). This is a separate, manually written field for each article.
  • body: Grabs the content from the article's "body" (正文) field and then shortens it. This is useful if you haven't written a description but want to show a snippet of the full article.

Basic Syntax

The body attribute is used within the dede:arclist loop. The most common way to use it is with the len and ellipsis attributes.

{dede:arclist titlelen='40' row='10'}
    <li>
        <a href="[field:arcurl/]">[field:title/]</a>
        <p>[field:body/]</p>
    </li>
{/dede:arclist}

Key Attributes for body

To control how the body text is displayed, you almost always use it with these helper attributes:

Attribute Description Example
len (Required) The maximum number of characters to display from the body. len='200'
ellipsis The text to append if the body text is truncated by the len attribute. The default is . ellipsis='[...]' or ellipsis='<'
infolen An alias for len. Both work the same way. infolen='100'

Practical Examples

Example 1: Basic Body Snippet

This example lists the 5 most recent articles, showing a 100-character snippet from the body of each.

<h2>Latest Articles</h2>
<ul>
    {dede:arclist row='5' orderby='pubdate'}
        <li>
            <strong><a href="[field:arcurl/]">[field:title/]</a></strong>
            <br>
            [field:body len='100' ellipsis='...']
        </li>
    {/dede:arclist}
</ul>

Output:

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

Latest Articles

  • How to Use DedeCMS DedeCMS is a powerful content management system... ...
  • A Guide to SEO Search Engine Optimization is crucial for getting your... ...
  • New Features in Version 5.7 We are excited to announce the release of our latest... ...

Example 2: Using a Custom Ellipsis

Sometimes, you might want to use a "Read More" link instead of just . You can achieve this by making the ellipsis an HTML link.

<h2>Read Our Blog</h2>
<div class="article-list">
    {dede:arclist row='3' titlelen='30'}
        <article>
            <h3><a href="[field:arcurl/]">[field:title/]</a></h3>
            <div class="excerpt">
                [field:body len='150' ellipsis='<a href="[field:arcurl/]">Read More</a>']
            </div>
        </article>
    {/dede:arclist}
</div>

Output:

Read Our Blog

Article Title One

This is a longer snippet from the article body. It will be cut off at 150 characters and then the link "Read More" will be appended... Read More

Article Title Two

Another article snippet with the same logic... Read More


Important Considerations and Best Practices

  1. Performance: Using body is slightly more resource-intensive than using description. This is because DedeCMS has to fetch the potentially very large body text from the database and then process it (strip HTML, truncate it). For lists with many articles (row='20' or more), this can slow down your page. For better performance, always use the description (info) field if you have manually written summaries.

  2. HTML and Images: The body attribute does not automatically strip HTML tags or image (<img>) tags. If your article body starts with <img src="...">, that's what will be displayed in your snippet.

    • Problem: [field:body len='50'] might output <img src="/uploads/image.jpg" alt="..."> which is not a text summary.
    • Solution: You need to use a modifier to strip the HTML. The textile modifier is excellent for this.
  3. The textile Modifier (Highly Recommended)

    To get a clean text-only summary, you should combine body with the textile modifier. textile removes all HTML tags and converts special characters.

    {dede:arclist}
        <p>
            [field:body function='cn_substr(@me, 100)'/]
        </p>
    {/dede:arclist}

    Explanation:

    • function='...': This allows you to run a PHP function on the field's value.
    • cn_substr(@me, 100): This is a common DedeCMS function.
      • @me: Represents the original value of the field (the full body text).
      • cn_substr: A custom function in DedeCMS similar to PHP's substr, but it handles Chinese characters correctly (avoiding cutting them in half).
      • 100: The length to truncate to.

    This combination gives you a clean, 100-character text snippet, free of any HTML.

Summary: body vs. description (Info)

Feature [field:body/] [field:description/] or [field:info/]
Source The full article body (正文) field. The manually written description ( field.
Content Can include HTML, images, etc. Plain text (or manually entered HTML).
Truncation Requires len or infolen attribute to be short. Not truncated by default. You must control its length in the backend.
Best For When you don't have descriptions and want an auto-generated snippet. Best practice. For performance and control, always use this for summaries.
Performance Slower for large lists. Faster.

Final Recommendation:

  • For performance and control, always use the description (info) field and write a summary for each article in the DedeCMS backend.
  • Use body only as a fallback or for specific cases where you need an automatic snippet and are okay with the slight performance hit. If you do use body, combine it with the textile modifier or a function to clean up the output.
-- 展开阅读全文 --
头像
dede list orderby如何按指定字段排序?
« 上一篇 2025-12-19
织梦SMTP服务器用户邮箱如何配置?
下一篇 » 2025-12-19

相关文章

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

目录[+]