dede arclist noflag参数如何实现不显示特定flag?

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

Of course! The noflag parameter in DedeCMS's {dede:arclist} tag is a very useful and commonly used attribute. Let's break it down in detail.

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

What is noflag?

In short, noflag is a parameter that excludes articles that have been flagged.

A "flag" in DedeCMS is a special marker or tag that you can assign to an article. This is often used for special features, such as:

  • "Recommendation" (推荐): Marking articles as featured or recommended.
  • "Headline" (头条): Marking articles for the top news section.
  • "Special" (专题): Marking articles that belong to a special topic.
  • "Carousel" (幻灯): Marking articles for a slideshow.
  • And more... You can define your own custom flags.

When you set noflag='yes' in your arclist tag, you are telling DedeCMS: "Show me all articles, except for the ones that have any of these flags."


How to Use noflag

The syntax is simple. You add the noflag attribute to your {dede:arclist} tag.

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

Basic Syntax

{dede:arclist noflag='yes'}
    <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 articles that are not flagged as "Recommendation", "Headline", "Special", etc.


Advanced Usage: Excluding Specific Flags

The real power of noflag comes when you want to exclude only some flags, not all of them. You can do this by specifying the flag codes.

Finding Flag Codes

First, you need to know the internal code for the flag you want to exclude. You can find this in your DedeCMS backend:

  1. Go to Content -> Article Manager -> Manage Articles.
  2. Click the "Advanced Search" button.
  3. Look for the "Flag" dropdown menu. The values in this dropdown are your flag codes.

Common default flag codes are:

dede arclist noflag
(图片来源网络,侵删)
  • c: Carousel (幻灯)
  • h: Headline (头条)
  • p: Picture (图文)
  • r: Recommend (推荐)
  • s: Special (专题)

Syntax for Excluding Specific Flags

You can exclude multiple flags by separating them with a comma ().

Example 1: Exclude only "Recommended" articles (r)

This is useful for creating a "Latest News" section that shouldn't include the featured articles from your "Recommended" section.

{dede:arclist noflag='r' titlelen='50' row='10'}
    <li>
        <a href="[field:arcurl/]" title="[field:title/]">[field:title function="cn_substr(@me, 50)"/]</a>
    </li>
{/dede:arclist}

Example 2: Exclude "Headline" and "Special" articles (h,s)

This is useful for a regular blog roll where you don't want the most important or special articles to clutter the list.

{dede:arclist noflag='h,s' row='15'}
    <li>
        <span>[field:pubdate function="MyDate('@me', 'm-d')"/]</span>
        <a href="[field:arcurl/]">[field:title/]</a>
    </li>
{/dede:arclist}

Practical Use Cases

Here are the most common scenarios where noflag is invaluable:

Use Case 1: Separate "Latest News" from "Featured Articles"

You might have two blocks on your homepage:

  • Block A (Featured): Shows only recommended articles (flag='r').
  • Block B (Latest): Shows the latest articles, but excludes the featured ones (noflag='r').
<!-- Block A: Featured Articles (only those with flag 'r') -->
<h2>Featured</h2>
{dede:arclist flag='r' titlelen='40' row='5'}
    <a href="[field:arcurl/]" title="[field:title/]">[field:title function="cn_substr(@me, 40)"/]</a>
{/dede:arclist}
<!-- Block B: Latest News (all articles EXCEPT those with flag 'r') -->
<h2>Latest News</h2>
{dede:arclist noflag='r' titlelen='40' row='10'}
    <a href="[field:arcurl/]" title="[field:title/]">[field:title function="cn_substr(@me, 40)"/]</a>
{/dede:arclist}

Use Case 2: A "Regular Blog" Section on a News Portal

A news portal might have sections for "Breaking News" (flag='h'), "Special Reports" (flag='s'), and a general "Technology" section. The Technology section should show all tech articles except the breaking news and special reports.

<h2>Technology News</h2>
{dede:arclist typeid='5' noflag='h,s' row='20'}
    <li>
        <a href="[field:arcurl/]">[field:title/]</a>
    </li>
{/dede:arclist}

(Note: typeid='5' is used here to filter by a specific category, which is often combined with noflag.)


Summary: flag vs. noflag

It's easy to confuse these two, so here's a quick reference:

Parameter Meaning Example What it Does
flag Include articles with these flags. {dede:arclist flag='r'} Shows only articles that are flagged as r (Recommended). Ignores all others.
noflag Exclude articles with these flags. {dede:arclist noflag='r'} Shows all articles except those that are flagged as r (Recommended).

By mastering noflag, you gain precise control over which articles appear in different parts of your website, allowing for more dynamic and well-structured content layouts.

-- 展开阅读全文 --
头像
dede list channelid标签如何指定栏目调用?
« 上一篇 12-07
dede织梦后台文章内容为何显示空白?
下一篇 » 12-07

相关文章

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

目录[+]