dede arclist continue 如何实现?

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

Of course! The dede:arclist tag is one of the most powerful and frequently used tags in DedeCMS. The "continue" functionality you're asking about is typically handled by two related but distinct concepts:

dede arclist continue
(图片来源网络,侵删)
  1. infolen: This limits the length of the article's summary (introtext).
  2. infosummary: This is a more advanced version of infolen that can also strip HTML tags.

Let's break down how to use them and other related parameters for achieving a "continue reading" effect.


The infolen Parameter (The Standard Method)

This is the most common way to control the length of the text displayed for each item in the list. It specifies the number of single-byte characters to show from the article's summary field (description).

Basic Syntax:

{dede:arclist row='10' titlelen='50' infolen='200'}
    <li>
        <a href="[field:arcurl/]">[field:title/]</a>
        <p>[field:info/]</p>
    </li>
{/dede:arclist}

Explanation:

dede arclist continue
(图片来源网络,侵删)
  • inflen='200': This is the key. It tells DedeCMS to take the first 200 characters from the article's summary (description field) and display it.
  • [field:info/]: This special field variable is automatically modified by the infolen parameter. You don't need to do anything else.

Important Consideration: The infolen parameter counts single-byte characters (like English letters, numbers, and symbols). A double-byte character (like a Chinese character, , , or ) typically counts as two characters.

  • If you set infolen='100' and your article summary is in Chinese, you will get approximately 50 Chinese characters.

The infosummary Parameter (The Advanced Method)

This is a more robust version of infolen. It not only limits the length of the text but also strips any HTML tags (like <p>, <strong>, <a>) from the summary before displaying it. This is very useful for ensuring clean, consistent formatting in your list.

Syntax:

{dede:arclist row='10' titlelen='50' infosummary='200'}
    <li>
        <a href="[field:arcurl/]">[field:title/]</a>
        <p>[field:info/]</p>
    </li>
{/dede:arclist}

Explanation:

dede arclist continue
(图片来源网络,侵删)
  • infosummary='200': This will take the first 200 characters from the summary and remove all HTML tags.
  • When to use infosummary vs. infolen:
    • Use infolen if your article summaries are plain text or if you want to preserve simple HTML formatting (like <strong> or <em>).
    • Use infosummary if your summaries might contain complex HTML (like <p> tags, lists, or images) that you don't want to appear in your short list view.

Creating a "Read More" Link

Simply limiting the text is only half the battle. A complete "continue reading" feature needs a link to the full article.

Here is a complete, practical example:

<h2>Latest Articles</h2>
<ul class="article-list">
    {dede:arclist row='5' titlelen='40' infolen='150'}
        <li>
            <!-- Display the title, linked to the full article -->
            <a href="[field:arcurl/]" class="article-title">[field:title/]</a>
            <!-- Display a short summary of the article -->
            <p class="article-summary">[field:info/]</p>
            <!-- Add a "Read More" link -->
            <a href="[field:arcurl/]" class="read-more">Continue Reading &raquo;</a>
        </li>
    {/dede:arclist}
</ul>

How it works:

  1. [field:arcurl/]: This variable holds the full URL to the individual article page. We use it in two places:
    • To make the article title clickable.
    • For the "Continue Reading" link itself.
  2. &raquo;: This is an HTML entity for the right-pointing double angle quotation mark (»), a common stylistic choice for "read more" links.

Other Useful Related Parameters

Here are a few other parameters that work well with arclist for fine-tuning your content display:

  • subday='N': Only display articles from the last N days.
    • Example: subday='7' shows articles from the last week.
  • typeid='N': Only display articles from a specific category ID.
    • Example: typeid='5,8,12' shows articles from categories with IDs 5, 8, and 12.
  • channelid='N': Only display articles from a specific model channel (e.g., Articles, Downloads, Products).
    • Example: channelid='1' is usually for articles.
  • flag='c': Only display articles marked as "recommended" or "special" (the c flag). You can combine flags, like flag='ch' for recommended and headlines.

Summary Table

Parameter Description Example
infolen Limits the summary to a number of single-byte characters. Preserves basic HTML. infolen='100'
infosummary Limits the summary and strips all HTML tags. Good for clean text. infosummary='100'
subday Filters articles by how many days old they are. subday='30' (last 30 days)
typeid Filters articles by specific category IDs. typeid='5,10'
[field:arcurl/] The essential variable for creating links to the full article. <a href="[field:arcurl/]">

By combining infolen or infosummary with a [field:arcurl/] link, you can easily create the "continue reading" effect you're looking for in DedeCMS.

-- 展开阅读全文 --
头像
C语言程序设计第二版 高等教育出版社,核心知识点是什么?
« 上一篇 11-29
织梦的数据库在phpmyadmin看不到
下一篇 » 11-29

相关文章

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

目录[+]