dede arclist idlist如何调用指定ID列表?

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

Of course! The idlist parameter is one of the most common and useful parameters for the DedeCMS (织梦CMS) {dede:arclist} tag. It allows you to manually specify which articles you want to display, bypassing any automatic sorting or filtering.

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

Here’s a complete guide on how to use idlist in {dede:arclist}.


What is idlist?

idlist is a parameter for the {dede:arclist} tag that lets you explicitly list the Article IDs (aid) of the articles you want to retrieve and display. This is extremely useful when you need to feature specific articles, create a "hand-picked" list, or display articles in a specific order that isn't covered by other parameters like orderway.

Syntax

The syntax is straightforward. You add the idlist attribute to your {dede:arclist} tag and provide a comma-separated list of the article IDs you want to include.

{dede:arclist idlist='文章ID1,文章ID2,文章ID3'}
    <li>
        <a href="[field:arcurl/]">[field:title/]</a>
        <span>[field:pubdate function="MyDate('Y-m-d',@me)"/]</span>
    </li>
{/dede:arclist}

How to Find an Article's ID (aid)

Before you can use idlist, you need to know the ID of the articles you want to display. Here are the easiest ways to find it:

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

Method 1: From the URL (The Quickest Way)

  1. Go to your DedeCMS backend.
  2. Navigate to ] -> [所有档案] (Content -> All Articles).
  3. Find the article you want and click its 编辑 (Edit) link.
  4. Look at the URL in your browser's address bar. It will look something like this: https://www.yourdomain.com/dede/arc_edit.php?aid=123
  5. The number after aid= is your article's ID. In this example, it's 123.

Method 2: From the Article Edit Page

  1. Follow steps 1-3 from Method 1.
  2. On the article edit page, look for the article's basic information. The ID is usually displayed prominently, often labeled as ID or 文档ID.

Method 3: Using SQL (For Power Users)

If you need to find IDs for many articles, you can run a simple SQL query in your database (e.g., via phpMyAdmin).

dede arclist idlist
(图片来源网络,侵删)
SELECT id, title FROM dede_archives LIMIT 20;

(Note: Replace dede_archives with your actual table prefix if it's different from dede)

Practical Examples

Let's say you found the IDs for three articles you want to feature: 15, 88, and 201.

Example 1: Basic Usage

This will display only the articles with IDs 15, 88, and 201.

<h2>Editor's Pick</h2>
<ul>
    {dede:arclist idlist='15,88,201' titlelen='30'}
        <li>
            <a href="[field:arcurl/]" title="[field:title/]">[field:title function='cn_substr(@me,30)'/]</a>
        </li>
    {/dede:arclist}
</ul>

Example 2: Controlling the Order

By default, articles in an idlist are displayed in the order you provide the IDs. This is a key advantage. If you want to display them in the order 201, 88, 15, just change the list:

<h2>Latest from Our Archives</h2>
<ul>
    {dede:arclist idlist='201,88,15'}
        <li>
            [field:pubdate function="MyDate('Y-m-d',@me)"] - <a href="[field:arcurl/]">[field:title/]</a>
        </li>
    {/dede:arclist}
</ul>

Example 3: Combining with Other Parameters

You can still use other arclist parameters alongside idlist. For instance, you can limit the number of items displayed (though with idlist, this is often redundant unless your list is long).

<!-- Display only the first 2 articles from the specified ID list -->
{dede:arclist idlist='15,88,201,45' row='2'}
    <div class="featured-post">
        <h3><a href="[field:arcurl/]">[field:title/]</a></h3>
        <p>[field:description function='cn_substr(@me,100)'/]...</p>
    </div>
{/dede:arclist}

Important Considerations and Troubleshooting

  • IDs Must Exist: If you include an ID in the list that does not exist in the dede_archives table, that article will simply be skipped, and no error will be shown.
  • No Commas at the End: Do not add a trailing comma to your ID list (e.g., idlist='15,88,'). This can sometimes cause unexpected behavior or errors in older DedeCMS versions.
  • Performance: Using idlist is generally very efficient because it performs a direct query for specific records, which is fast. It's often more performant than filtering by category or keyword if you know the exact IDs you need.
  • Cache: Remember that DedeCMS caches its templates. If you make changes to an arclist tag, you may need to clear the cache (go to [系统] -> [HTML更新] -> [更新HTML]) to see the changes on the front end.

Summary

Parameter Value Description
idlist '15,88,201' A comma-separated string of article IDs (aids) to display. The order in the string is the display order.

In short, idlist is your go-to parameter for creating curated, hand-picked article lists on your DedeCMS website.

-- 展开阅读全文 --
头像
macossublime编译C语言
« 上一篇 12-07
织梦SMS网站如何更换广告图片?
下一篇 » 12-07

相关文章

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

目录[+]