dede:arclist标签如何设置每页显示数量?

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

Of course! The dede:arclist tag is one of the most frequently used tags in DedeCMS. The pagesize attribute is essential for controlling how many articles are displayed on a page.

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

Here's a complete guide on how to use pagesize in dede:arclist.


What is pagesize?

The pagesize attribute in the dede:arclist tag specifies the maximum number of articles to display on a single page.

  • Purpose: To limit the output, preventing a single page from becoming too long and to enable pagination.
  • Default Value: If you don't set pagesize, DedeCMS uses its default setting, which is typically 10 articles per page. It's best practice to always define it explicitly.

Basic Syntax

The attribute is added directly inside the dede:arclist tag.

{dede:arclist pagesize='20' ...}
    <!-- Article template code here -->
    <li>
        <a href="[field:arcurl/]">[field:title/]</a>
        <span>[field:pubdate function="MyDate('@me', 'Y-m-d')"/]</span>
    </li>
{/dede:arclist}

In this example, the list will display a maximum of 20 articles.

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

Practical Examples

Example 1: Displaying 5 Articles in the Homepage Sidebar

This is a common use case for a "Latest News" widget in a sidebar.

<h3>Latest News</h3>
<ul class="sidebar-news">
    {dede:arclist pagesize='5' titlelen='30' orderby='pubdate'}
        <li>
            <a href="[field:arcurl/]" title="[field:title/]">[field:title function='cn_substr(@me, 30)'/]</a>
        </li>
    {/dede:arclist}
</ul>
  • pagesize='5': Shows only 5 articles.len='30'`: Limits the title length to 30 characters.
  • orderby='pubdate': Orders articles by their publication date, newest first.

Example 2: Creating an Article List Page with Pagination

When you use pagesize, DedeCMS automatically generates the necessary pagination links (< Previous 1 2 3 Next >) at the end of the list, provided you have the pagination template tag in your HTML.

Template File (e.g., list_article.htm)

<!DOCTYPE html>
<html>
<head>{dede:field.title/} - {dede:global.cfg_webname/}</title>
</head>
<body>
    <h1>{dede:field.title/}</h1>
    <!-- The article list using pagesize -->
    <ul class="article-list">
        {dede:arclist pagesize='15' titlelen='50' orderby='pubdate'}
            <li>
                <a href="[field:arcurl/]" title="[field:title/]">[field:title/]</a>
                <p class="summary">[field:description function='cn_substr(@me, 150)'/]...</p>
                <span class="date">[field:pubdate function="MyDate('@me', 'Y-m-d')"/]</span>
            </li>
        {/dede:arclist}
    </ul>
    <!-- THIS IS THE KEY FOR PAGINATION -->
    <div class="page-nav">
        {dede:pagelist listsize='5' listitem='pre,next,pageno'}
        </div>
    </div>
</body>
</html>
  • pagesize='15': Each page will show 15 articles.
  • {dede:pagelist ...}: This is the tag that renders the pagination links. It works in conjunction with pagesize.
    • listsize='5': Shows 5 page numbers in the list (e.g., ... 5 6 7 8 9 ...).
    • listitem='pre,next,pageno': Specifies which items to display: Previous link, Next link, and Page Numbers.

Troubleshooting Common Issues

Issue 1: Pagination Links Don't Appear

Problem: You set pagesize, but you don't see the "Previous 1 2 3 Next" links.

Solution: You are missing the {dede:pagelist} tag in your template file. Make sure you add it after the {/dede:arclist} closing tag.

Issue 2: Pagination Links Are Broken (404 Error)

Problem: The pagination links are there, but clicking on them gives a "Page Not Found" error.

Solution: This is almost always a problem with your URL or rewrite rules.

  1. Check your URL settings in DedeCMS backend:
    • Go to "System" -> "System Basic Parameters" -> "Core Settings".
    • Look for "Article Path Setting". It should be set to something like /{typedir}/{Y}/{M}/{D}/{aid}.html or /{typedir}/{aid}.html.
  2. Check your .htaccess file (if using Apache mod_rewrite):
    • Ensure the rewrite rules for pagination are correct. The default DedeCMS .htaccess usually handles this automatically, but if you've modified it, you might have broken the pagination logic. A common rule looks like this:
      RewriteRule ^list-([0-9]+)-([0-9]+)\.html$ /plus/list.php?tid=$1&PageNo=$2
    • The key is the PageNo=$2 part, which tells DedeCMS which page number is being requested.

Important Related Attributes

pagesize works best when combined with other attributes for precise control.

Attribute Description Example
typeid Limits articles to a specific category or list of categories. typeid='5,8,12'
channelid Limits articles to a specific content model (e.g., articles, downloads). channelid='1' (for articles)
orderby Sorts the articles. Common values: pubdate (date), hot (clicks), sortrank (manual order). orderby='hot'
orderway Sets the sort order: desc (descending) or asc (ascending). orderway='desc'
infolen The length of the article summary (description). infolen='200'

Summary

To use pagesize effectively:

  1. Add pagesize='N' to your dede:arclist tag, where N is the number of articles per page.
  2. Add {dede:pagelist ...} to your template to display the pagination links.
  3. Check your URL and .htaccess settings if pagination links result in a 404 error.
-- 展开阅读全文 --
头像
100例单片机C代码实训,如何快速掌握程序设计?
« 上一篇 11-29
数据结构1000问,C语言如何解千题?
下一篇 » 11-29

相关文章

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

目录[+]