dede list limit

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

Of course! The dede:list tag in DedeCMS (织梦CMS) is one of the most commonly used tags for displaying lists of articles. The limit attribute is essential for controlling how many articles are shown in that list.

Here's a comprehensive guide on how to use the dede:list limit attribute, from basic usage to advanced examples.


Basic Syntax of dede:list

The dede:list tag is used within an article list template file (usually list_*.htm).

{dede:list}
    <!-- The HTML template for each article item -->
    <li>
        <a href="[field:arcurl/]">[field:title/]</a>
        <span>[field:pubdate function="MyDate('Y-m-d',@me)"/]</span>
    </li>
{/dede:list}

The limit attribute is added directly inside the opening {dede:list} tag.

{dede:list limit='start,count'}
    <!-- Template for each article -->
{/dede:list}

The limit Attribute Explained

The limit attribute accepts a string with two parts, separated by a comma: start,count.

  • start: The offset, or the number of articles to skip from the beginning of the list. It's zero-based (the first article is 0).
  • count: The total number of articles to display after the offset.

Example Breakdown:

  • limit='10': This is a shortcut. It means start=0 and count=10. It will display the first 10 articles.
  • limit='0,10': Same as above. Displays articles 1 through 10.
  • limit='10,10': Skips the first 10 articles (start=10) and then displays the next 10 articles (count=10). This shows articles 11 through 20.
  • limit='20,5': Skips the first 20 articles and displays the next 5. This shows articles 21 through 25.

Practical Examples

Let's imagine your channel has 50 articles. Here are some common scenarios:

Example 1: Display the Latest 10 Articles (Most Common)

This is the default behavior if no limit is specified, but it's good to be explicit.

{dede:list limit='10'}
    <li>
        <a href="[field:arcurl/]">[field:title/]</a>
    </li>
{/dede:list}

Result: Articles 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.

Example 2: Display Articles 11 to 20 (Pagination on the First Page)

This is useful if you want to, for example, show a "Featured" section with the first 10 articles and then a "Latest News" section starting from the 11th.

<h2>Latest News (Starting from Article 11)</h2>
<ul>
    {dede:list limit='10,10'}
        <li>
            <a href="[field:arcurl/]">[field:title/]</a>
            <span>[field:pubdate function="MyDate('Y-m-d',@me)"/]</span>
        </li>
    {/dede:list}
</ul>

Result: Articles 11, 12, 13, 14, 15, 16, 17, 18, 19, 20.

Example 3: Display a Specific Number of Articles (e.g., 5)

If you just want to show a small, fixed number of items in a sidebar or a box.

<div class="hot-articles">
    <h3>Hot Articles</h3>
    {dede:list limit='5'}
        <div class="hot-item">
            <i>[field:global.autoindex/]</i>
            <a href="[field:arcurl/]">[field:title/]</a>
        </div>
    {/dede:list}
</div>

Result: Articles 1, 2, 3, 4, 5.


Advanced Usage: Combining with orderby and orderway

The limit attribute works in conjunction with other dede:list attributes to control the order of the articles before the limit is applied.

  • orderby: The field to sort by. Common values: pubdate (publication date), click (click count), id (article ID).
  • orderway: The sort direction. desc for descending (newest first, highest clicks first), asc for ascending (oldest first).

Example: Display the Top 5 Most Clicked Articles

<h2>Most Popular Articles</h2>
<ul>
    {dede:list limit='5' orderby='click' orderway='desc'}
        <li>
            <a href="[field:arcurl/]">[field:title/]</a>
            <span>Views: [field:click/]</span>
        </li>
    {/dede:list}
</ul>

Result: This will first sort all articles by click in descending order and then take the top 5 from that sorted list.


Important Considerations & Troubleshooting

a. The pagesize Attribute in the Channel

The limit attribute of dede:list can be overridden by the "List page size" (列表每页显示数) setting for that specific channel.

  • How to check: Go to your DedeCMS backend -> Content -> Channel Manager (频道管理). Click "Edit" (修改) on the channel you are working with. On the "Advanced options (高级选项)" tab, you will see "List page size (列表每页显示数)".
  • What it does: If you set this to 10 in the channel settings, {dede:list limit='20'} will still only show 10 articles. The limit in the template is ignored in favor of the channel's global setting.

Solution: If your limit attribute doesn't seem to be working, the first thing to check is the channel's pagesize setting.

b. Difference between dede:list and dede:arclist

Feature dede:list dede:arclist
Usage Used in list templates (list_*.htm). Can be used in any template (index, article, list, etc.).
Performance Faster. It directly queries the list of articles for the current channel. Slower. It performs a more complex query to get a list of articles from across the site, based on its parameters.
Pagination Automatically handles pagination. It knows which page it's on and calculates the articles accordingly. Does not handle pagination automatically. You must use row and titlelen to control the number of items. It's for a fixed list.
Recommendation Always use dede:list inside a list template. Use dede:arclist for sidebars, footers, or any place you need to pull a small, specific list of articles from a channel or multiple channels.

For simple list displays in your list_*.htm files, stick with {dede:list}. It's more efficient and designed for that exact purpose.

-- 展开阅读全文 --
头像
织梦 utf8 编辑器
« 上一篇 01-08
c语言内存不能为written
下一篇 » 01-08

相关文章

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

目录[+]