dede list pagesize参数如何设置?

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

Of course! The dede:list tag is one of the most fundamental and frequently used tags in DedeCMS (织梦CMS). Its primary purpose is to list articles from a specific channel or category. The pagesize attribute is crucial for controlling how many articles are displayed on each page of the list.

dede list pagesize
(图片来源网络,侵删)

Here’s a comprehensive guide to the dede:list tag and the pagesize attribute.


What is pagesize?

The pagesize attribute sets the number of articles to display per page on a list page (e.g., list_article.htm).

When you have more articles than pagesize, DedeCMS automatically handles the pagination, creating links like "Page 1", "Page 2", "Next", etc., at the bottom of the list.

Basic Syntax

The dede:list tag is used within a list template file (e.g., list_article.htm).

dede list pagesize
(图片来源网络,侵删)
{dede:list pagesize='20'}
    <li>
        <a href='[field:arcurl/]'>[field:title/]</a>
        <span>[field:pubdate function="MyDate('Y-m-d',@me)"/]</span>
    </li>
{/dede:list}

Explanation:

  • {dede:list pagesize='20'}: This opens the list loop and sets the page size to 20 articles per page.
  • The HTML and other DedeCMS tags inside this loop will be repeated for each article.
  • [field:arcurl/]: Displays the full URL of the article.
  • [field:title/]: Displays the title of the article.
  • [field:pubdate ... /]: Displays the publication date. The function is used to format the date into a "Y-m-d" (e.g., 2025-10-27) format.
  • {/dede:list}: Closes the loop.

How to Use pagesize in Practice

Step 1: Edit the List Template

  1. Log in to your DedeCMS backend.
  2. Go to 模板 (Templates) -> 默认模板管理 (Default Template Management).
  3. Find the template file for your channel's list page. It's usually named list_*.htm (e.g., list_article.htm for the article channel, list_product.htm for a product channel).
  4. Edit this file. Locate the {dede:list} tag.
  5. Add the pagesize attribute with your desired value.

Example: Displaying 10 articles per page

{dede:list pagesize='10'}
    <div class="post-item">
        <h2><a href="[field:arcurl/]" title="[field:title/]">[field:title/]</a></h2>
        <div class="post-meta">
            <span class="date">[field:pubdate function="MyDate('Y-m-d',@me)"]</span>
            <span class="category">Category: [field:typename/]</span>
        </div>
        <p class="excerpt">[field:description/]...</p>
    </div>
{/dede:list}

Step 2: (Optional) Adjust Pagination Settings

While pagesize controls the number of items per page, you might also want to control the pagination block itself. This is done using the {dede:pagelist} tag.

The {dede:pagelist} tag is usually placed right after the {dede:list} loop.

dede list pagesize
(图片来源网络,侵删)

Example of a complete list page with pagination:

<html>
<head>{dede:field.title/}</title>
</head>
<body>
    <h1>{dede:field.title/}</h1>
    <!-- The article list -->
    {dede:list pagesize='10'}
        <div class="post-item">
            <h2><a href="[field:arcurl/]" title="[field:title/]">[field:title/]</a></h2>
            <div class="post-meta">
                <span class="date">[field:pubdate function="MyDate('Y-m-d',@me)"]</span>
            </div>
        </div>
    {/dede:list}
    <!-- The pagination links -->
    <div class="pagination">
        {dede:pagelist listsize='4' listitem='info,index,end,pre,next,pageno'}
        </div>
    </div>
</body>
</html>

Explanation of {dede:pagelist} attributes:

  • listsize='4': Shows 4 page numbers on each side of the current page.
  • listitem='...': Controls which parts of the pagination to display.
    • info: Shows info like "Total 50 articles, 5 pages".
    • index: Shows "Home".
    • pre: Shows "Previous".
    • next: Shows "Next".
    • end: Shows "Last".
    • pageno: Shows the page numbers (e.g., 1, 2, 3).

Troubleshooting and Common Issues

Issue: pagesize is not working. The page shows all articles.

This is a very common problem. The reason is almost always a cache issue.

Solution: Clear the Cache.

  1. Clear the Site Cache: In the DedeCMS backend, go to 系统 (System) -> 系统基本参数设置 (System Basic Settings) -> 性能选项 (Performance Options) and click "Clear All Cache".
  2. Clear the Template Cache: Go to 模板 (Templates) -> 模板引擎管理 (Template Engine Management) and click "Clear All Cache".
  3. Clear the Browser Cache: Press Ctrl + F5 (or Cmd + Shift + R on Mac) to hard refresh your browser page.

After clearing the cache, the pagesize setting should take effect immediately.

Issue: The pagesize value is ignored and it's using a different value.

This can happen if you have multiple places defining the page size. DedeCMS has a system-level default.

Solution: Check the System Default.

  1. Go to 系统 (System) -> 系统基本参数设置 (System Basic Settings).
  2. Find the option named 列表每页显示行数 (Number of items displayed per page in lists).
  3. If you set a value here, it will be the default for all lists that don't explicitly use the pagesize attribute. Your pagesize='10' in the template will override this default.

Summary

Element Purpose Example
{dede:list} The main loop for displaying a list of articles. {dede:list ...}
pagesize Attribute of {dede:list} to set items per page. {dede:list pagesize='15'}
{dede:pagelist} Tag to display pagination links (Next, Previous, Page numbers). {dede:pagelist ...}
{dede:field.title/} Displays the title of the current category/channel. <h1>{dede:field.title/}</h1>

By correctly using the pagesize attribute within the {dede:list} tag and clearing the cache when needed, you can easily control how many articles are shown on each list page in your DedeCMS website.

-- 展开阅读全文 --
头像
dede field.content字段内容如何获取或显示?
« 上一篇 2025-12-13
韩顺平dede二次开发视频百度网盘有吗?
下一篇 » 2025-12-13

相关文章

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

目录[+]