dede list noflag标签如何实现排除特定flag?

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

Of course. Let's break down the noflag parameter in the DedeCMS (dedecms) {dede:list} tag.

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

What is {dede:list}?

First, it's important to understand what {dede:list} does. It's a core DedeCMS tag used to list articles or other documents from a specific channel or category. It's typically used in templates to generate a list of articles, for example, on a category page, an archive page, or a search results page.

The basic syntax is:

{dede:list row='10' titlelen='40' orderby='default'}
    <li>
        <a href='[field:arcurl/]'>[field:title/]</a>
        <span>[field:pubdate function="MyDate('Y-m-d',@me)"/]</span>
    </li>
{/dede:list}
  • row: The number of articles to display.len`: The length of the title to display.
  • orderby: The order of articles (e.g., pubdate for publish date, hot for hits, sortrank for manual sorting).

What is the noflag Parameter?

The flag parameter in DedeCMS is a powerful feature used to mark an article with one or more special statuses or attributes. These flags are stored in the flag field of the dede_archives table as a sum of binary values.

Common flags include:

dede list noflag
(图片来源网络,侵删)
  • c: Recommended (推荐)
  • h: Headline (头条)
  • p: Picture (图文)
  • s: Special (专题)
  • j: Jump (跳转)
  • a: Article (普通文章)
  • b: Bold (加粗)

By default, when you use {dede:list}, it will fetch all articles, regardless of their flags. This is where noflag becomes useful.

The noflag parameter is a filter that tells DedeCMS to exclude articles that have any of the specified flags.


How to Use noflag

You add the noflag parameter directly inside the {dede:list} opening tag.

Syntax:

{dede:list row='10' titlelen='40' noflag='chp'}
    <!-- Your list item template here -->
{/dede:list}

In this example, noflag='chp' means: "Do not show articles that have the 'c' (Recommended), 'h' (Headline), or 'p' (Picture) flags."

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

Practical Examples

Let's imagine you have a website with different types of content. You want to create a clean, simple list of "standard" articles, excluding any special or featured content.

Example 1: Excluding Recommended and Headline Articles

You want to list articles but exclude those marked as "Recommended" (c) or "Headline" (h).

<h2>Latest Standard Articles</h2>
<ul>
    {dede:list row='8' orderby='pubdate' noflag='ch'}
        <li>
            <a href="[field:arcurl/]" title="[field:title/]">[field:title/]</a>
            <span class="date">[field:pubdate function="MyDate('Y-m-d',@me)"]</span>
        </li>
    {/dede:list}
</ul>

What this does: It will display the 8 most recently published articles that are not flagged as Recommended or Headline.

Example 2: Excluding Only Jump Articles

Sometimes, articles with the jump flag (j) are external links and you don't want them in your regular article lists.

<h2>Our Internal Articles</h2>
<ul>
    {dede:list row='15' noflag='j'}
        <li>
            <a href="[field:arcurl/]">[field:title/]</a>
        </li>
    {/dede:list}
</ul>

What this does: It will list 15 articles, ensuring that any article marked as a "Jump" link is excluded from the results.

Example 3: Using flag vs. noflag for Comparison

To better understand the difference, let's look at the opposite: the flag parameter.

  • flag: To show articles that have at least one of the specified flags.

    • {dede:list flag='c'}: Shows only articles that are Recommended.
    • {dede:list flag='ch'}: Shows articles that are either Recommended or Headline.
  • noflag: To show articles that have none of the specified flags.

    • {dede:list noflag='c'}: Shows all articles except those that are Recommended.
    • {dede:list noflag='ch'}: Shows all articles except those that are Recommended or Headline.

Important Considerations

  1. Case-Insensitive: The flag letters (c, h, p) are case-insensitive, but the convention is to use lowercase.
  2. Combination with Other Parameters: You can use noflag alongside other parameters like row, orderby, and typeid.
    {dede:list typeid='5' row='5' orderby='hot' noflag='c'}

    This would list the 5 most popular (orderby='hot') articles from category ID 5, excluding any that are recommended (noflag='c').

  3. Performance: For very large sites with thousands of articles, using complex flag or noflag filters can have a minor impact on query performance. However, for most standard websites, the impact is negligible.

Summary

Parameter Purpose Example
flag Includes articles that have at least one of the specified flags. {dede:list flag='c'} (Shows only Recommended articles)
noflag Excludes articles that have any of the specified flags. {dede:list noflag='c'} (Shows all articles except Recommended ones)

In short, noflag is your go-to parameter when you want to create a "clean" list of articles by filtering out special or promoted content.

-- 展开阅读全文 --
头像
dede position 样式
« 上一篇 2025-12-28
dede install dir
下一篇 » 2025-12-28

相关文章

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

目录[+]