dede arclist标签row=10参数如何设置?

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

Of course! The dede:arclist tag is one of the most frequently used tags in DedeCMS (织梦CMS). It's used to display a list of articles, often on the homepage, category pages, or in sidebars.

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

The row attribute is essential for controlling how many articles appear in the list.


Basic Syntax and the row Attribute

The row attribute specifies the maximum number of articles to display in the list.

Basic Structure:

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

Explanation of the row='10' part:

dede arclist row 10
(图片来源网络,侵删)
  • row: The attribute name.
  • 10: The value, which means "show a maximum of 10 articles".
  • DedeCMS will fetch the 10 most recently published articles (based on their sorting rules) and display them.

Complete Example: A List of 10 Latest Articles

Here is a practical example you can use on your homepage to show the 10 latest articles from all sections.

<h3>Latest Articles</h3>
<ul class="article-list">
    {dede:arclist row='10' titlelen='30' orderby='pubdate' orderway='desc'}
    <li>
        <span class="date">[field:pubdate function="MyDate('Y-m-d',@me)"/]</span>
        <a href="[field:arcurl/]" title="[field:title function='html2text(@me)'/]">[field:title/]</a>
    </li>
    {/dede:arclist}
</ul>

Breakdown of this example:

  • {dede:arclist row='10' ...}: Sets the list to a maximum of 10 articles.len='30'`: Limits the title to 30 characters to prevent layout issues.
  • orderby='pubdate': Sorts the articles by their publication date. Other common values are id, click (for most clicked), and hot (for hottest).
  • orderway='desc': Sets the sort order to descending (newest first). Use asc for ascending (oldest first).
  • [field:pubdate ...]: Displays the article's publication date. We use a function (MyDate) to format it nicely.
  • [field:arcurl/]: Generates the full URL to the article's detail page.
  • [field:title/]: Displays the article's title.

Commonly Used Attributes with arclist

Often, you'll use row along with other attributes to fine-tune your list.

Attribute Description Example
typeid (Important) Specifies the category ID to pull articles from. Use 0 for all sections. typeid='0' (all), typeid='5' (from category with ID 5)
channelid Specifies the channel ID (e.g., articles, downloads, products). channelid='1' (default article channel)
limit Sets a range for the results. start,row. For example, to skip the first 5 and show the next 10. limit='5,10'
infolen Maximum length of the article summary (introtext). infolen='100'
orderby Field to sort by. pubdate, id, click, hot. orderby='click'
orderway Sort order: desc (descending) or asc (ascending). orderway='desc'
flag Filter by article flags. h (headline), c (commend), p (picture). flag='h,c' (headlines and recommended)
subday Only show articles from the last N days. subday='30' (articles from the last 30 days)

Practical Use Cases

Use Case 1: Show 5 Articles from a Specific Category

Let's say you have a category "News" with ID=5. You want to show the 5 latest articles from just that category.

dede arclist row 10
(图片来源网络,侵删)
<h3>Latest News</h3>
<ul>
    {dede:arclist row='5' typeid='5' titlelen='25'}
    <li><a href="[field:arcurl/]">[field:title/]</a></li>
    {/dede:arclist}
</ul>

Use Case 2: Show 10 Most Clicked Articles from All Categories

To create a "Popular Articles" widget, you sort by the click count.

<h3>Popular Articles</h3>
<ol>
    {dede:arclist row='10' orderby='click' orderway='desc'}
    <li><a href="[field:arcurl/]" title="[field:title function='html2text(@me)'/]">[field:title/]</a></li>
    {/dede:arclist}
</ol>

Use Case 3: Show 10 Articles with Images (Flag 'p')

To get articles that have a thumbnail, you can use the flag attribute.

<div class="image-gallery">
    {dede:arclist row='10' flag='p' orderby='pubdate' orderway='desc'}
    <div class="item">
        <a href="[field:arcurl/]">
            <img src="[field:litpic/]" alt="[field:title function='html2text(@me)'/]">
            <span>[field:title/]</span>
        </a>
    </div>
    {/dede:arclist}
</div>

Troubleshooting

  • Why are no articles showing?

    1. typeid is wrong: Double-check the ID of your category. You can find category IDs in DedeCMS's backend under "Content" -> "Category Management".
    2. No articles in the category: Make sure the category you are querying actually has articles in it.
    3. Template Caching: Sometimes, changes don't appear immediately due to template caching. Try clearing the cache in DedeCMS's backend under "System" -> "Clear Cache".
  • Why are more than 10 articles showing?

    • You might have another arclist tag on the same page that is pulling more articles. Check your entire template file. The row attribute is specific to each individual {dede:arclist} tag.
-- 展开阅读全文 --
头像
dede cfg mb editday是什么配置参数?
« 上一篇 12-07
dede field.keywords是什么?如何使用?
下一篇 » 12-07

相关文章

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

目录[+]