How does the `pageList` tag in Anqi CMS display all single page lists and exclude specific pages?

Calendar 👁️ 74

AnQi CMS is a flexible and efficient content management system that provides strong support for our website operations, whether it is publishing articles, managing products, or creating various single pages, it shows great skill. Today, let's talk about a very practical skill when using AnQi CMS to manage single pages: how topageListThe tag displays all single pages and can accurately exclude specific pages that we do not want to display.

In the daily operation of websites, we often create some single-page pages such as "About Us", "Contact Information", "Privacy Policy" and so on.Most of the time, we hope to list these pages uniformly in the navigation menu or some area for easy user access.AnQi CMS provides a convenient template tag for this——pageListIt can help us easily obtain the list of all single pages on the website.

pageListBasic usage of tags

To get the list of all single-page lists of the website,pageListThe use of tags is very intuitive. We usually write template code like this:

{% pageList pages %}
    <ul class="page-nav">
    {% for item in pages %}
        <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
    {% endfor %}
    </ul>
{% endpageList %}

In this code block,{% pageList pages %}Will fetch all single-page data from the background database and store it in a variable namedpages. Next, we use{% for item in pages %}Loop through thispagesthe list,itemto represent each single page in the list. By{{ item.Link }}We can get the link of the page, and{{ item.Title }}then we can display the title of the page. In this way, a navigation list containing all single pages appears in front of us.

Flexible customization: Exclude specific pages

AlthoughpageListIt is convenient to list all pages, but in actual operation, we may encounter such needs: some single pages, such as internal drafts, temporary event pages, or some pages that are only accessible through specific links and do not want to appear in the general list, we do not want them to appear bypageListThe generated list contains.

Of Security CMSpageListThe tag itself does not provide a direct 'exclude ID' parameter, but its template engine is very flexible, allowing us to make conditional judgments while traversing the list, thus achieving customized content display.This is the key to excluding specific pages.

We can do this byforAdd within the loopifCondition judgment, to check whether the current page being traversed is the page we want to exclude.If it meets the exclusion criteria, we will skip this page and not display it.The most commonly used criterion is the page ID, as the page ID is unique and stable.

Operation steps:

  1. Get the page ID to exclude:Log in to the AnQi CMS backend, go to the 'Page Resources' under 'Page Management'.Here, you can see the 'ID' column for each single page.Write down the ID of the page you want to exclude.

  2. Add the exclusion logic in the template:Assuming we want to exclude ID of1(For example, an early version of "About Us" or an internal test page) and ID is5(For example, the "Special Event Login Page") page. We can modify the above template code to addifJudgment:

    {% pageList pages %}
        <ul class="page-nav">
        {% for item in pages %}
            {# 判断当前页面的ID是否为1或5。如果是,则不显示它 #}
            {% if not (item.Id == 1 or item.Id == 5) %}
            <li class="page-item">
                <h3 class="page-title"><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
                {# 你还可以根据需要显示更多页面信息,例如缩略图或简介 #}
                {% if item.Thumb %}
                <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="page-thumb">
                {% endif %}
                <p class="page-description">{{ item.Description|truncatechars:100 }}</p>
                <a href="{{ item.Link }}" class="read-more">查看详情</a>
            </li>
            {% endif %}
        {% endfor %}
        </ul>
    {% endpageList %}
    

    In the modified code section,{% if not (item.Id == 1 or item.Id == 5) %}This line is core. It first checks the ID of the current page (item.Id) whether it is equal to1or5. If it is equal to any of them, thenitem.Id == 1 or item.Id == 5this condition will be true, the previousnotIt will be converted to false, thus skipping<li>...</li>This code, the page will not be rendered. Only when the ID of the page is not1nor5then,not (...)The condition is true, the page content will be displayed normally.

    If you only want to exclude one page, the code will be more concise:{% if item.Id != 1 %}.

Consideration of practical application scenarios

This way of excluding specific pages is very useful in many scenarios:

  • Draft or test pages:During development or content update, some incomplete or testing single pages may exist, and we do not want them to be mistakenly clicked by users.
  • Non-public page:Some single pages may be for internal use only, or accessible through specific promotional links, without needing to be exposed in public navigation.
  • Redundant or outdated pages: If the website has some merged or outdated single pages that are not convenient to delete temporarily for historical data or SEO considerations, we can also exclude them from the main list.

In this way, we can flexibly control the display of content without modifying the core tag function, allowingpageListLabels maintain their convenience while also fitting our refined operational needs.


Frequently Asked Questions (FAQ)

1. Besides using ID, can I exclude pages in other ways?Of course, each.item(Single-page) The object also excludesIdand includesTitle(Title),Link(Link),Description(Description) and other fields. You can judge according to these fields. For example, if you want to exclude pages with the title containing 'internal', you can use{% if not (item.Title|contain:"内部") %}. However, usingIdIt is usually the most stable and recommended method, as the ID is a unique numeric identifier that is not easily affected by content changes or URL structure adjustments.

2. If I want to exclude a lot of pages, writing them one by oneorWouldn't it be麻烦?When there are a lot of page IDs to exclude, usingorIndeed, connecting makes the code verbose. A more concise way is to first define a list of IDs to exclude in a variable, then checkitem.IdIs it included in this list. For example,{% set exclude_ids = [1, 5, 10, 12] %}Then, judge in the loop{% if not (item.Id in exclude_ids) %}This can greatly improve the readability and maintainability of the code.

3. Is this exclusion logic dynamic? If I change the status of the page in the background (for example, to draft), will it take effect in the list immediately?Yes, this exclusion logic is dynamic. Each time a user visits the page, the Anqi CMS will execute the template code in real-time to generate content.This means that if you modify the page ID in the background or change the content of a field used for judgment (such as the title), these changes will be reflected immediately inpageListGenerated list, as long as they trigger the conditions you setifNo manual cache clearing is needed.

Related articles

How to effectively display the description (Description) and content (Content) on the front page?

In AnQi CMS, the description (Description) and content (Content) are key elements for website content organization and search engine optimization (SEO).Effectively display this information on the front page, not only providing visitors with clear navigation and in-depth information, but also helping search engines better understand the theme of the page, thereby improving the visibility of the website.Let's explore how to flexibly display the description and content of categories in the Anqi CMS front-end template together.

2025-11-09

How to get and display the custom Banner image group of the `categoryDetail` tag?

In website operation, configuring unique visual elements for different category pages, such as customized banner image groups, is crucial for enhancing user experience and strengthening brand recognition.AnQiCMS (AnQiCMS) leverages its flexible content management capabilities, allowing users to easily set up exclusive Banners for each category and provides intuitive template tags for conveniently displaying these contents on the frontend page.We all know that when users browse a website, the category page is a key entry point for them to explore content.

2025-11-09

How to build and display a multi-level product category navigation in AnQi CMS?

AnQi CMS is a powerful content management system that provides users with the ability to flexibly build and display multi-level product classification navigation.This not only helps website visitors easily find the products they need, but also effectively improves the website's SEO performance and optimizes the user experience.Let's explore together how to achieve this goal in Anqi CMS. ### Core Basics: Understanding the Classification System of AnQi CMS In AnQi CMS, the construction of multi-level product classification navigation is inseparable from its core "content model" and "document classification" functions. First

2025-11-09

How to display custom fields (such as author, source) of AnQi CMS documents on the front-end page?

When managing content in Anqi CMS, we often encounter the need to add more personalized data to articles, products, or pages, such as the author of the article, the source of content, or specific parameters of products, or specific attributes of event pages, etc.This additional customization information is called "custom field".The powerful content model function of AnQi CMS makes it very convenient to create and manage custom fields, and more importantly, how to accurately and beautifully present these meticulously entered custom fields on the front page of the website

2025-11-09

How to retrieve and display all the detailed content of a single page, including the slide group image, using the `pageDetail` tag?

In Anqi CMS, a single page is an indispensable part of the website structure, commonly used to display 'About Us', 'Contact Information', 'Service Introduction', etc., which are relatively fixed and do not require frequent updates.For these pages, we usually want to be able to flexibly control the way content is displayed, including text, images, and even slide group images.The `pageDetail` tag is born for this, it allows us to easily retrieve and display all the detailed content of a single page.###

2025-11-09

How to use the `guestbook` tag to build and display a dynamic guestbook form on the front page?

In AnQiCMS, building a functional message form is an important way to interact effectively with users, collect feedback, or obtain potential customer information.It is pleasing that with its powerful template tag system, especially the `guestbook` tag, we can easily create and display a dynamic and flexible guestbook form on the front page without writing complex backend code.The core of flexibly building a message form

2025-11-09

How to display the friend link list in the website background configuration of Anqi CMS?

In website operation, friendship links are an important link to enhance website weight, increase traffic, and improve user experience.AnQiCMS (AnQiCMS) provides us with a convenient way to manage and display these links.How can the list of friend links configured on the back-end be displayed on the website front-end?This is actually simpler than imagined, mainly involving two steps: backend configuration and frontend template invocation. ### Step 1: Configure the友情链接 in the background Firstly, we need to add and manage the friendship links in the Anq CMS background management system.According to system design

2025-11-09

How to use the `pagination` tag to generate a page navigation that conforms to user habits for articles or product lists?

In website operation, how to allow users to easily browse a large amount of content and find the information they are interested in is a crucial topic.Especially on pages such as article lists and product displays, reasonable pagination navigation not only improves user experience but is also an indispensable part of search engine optimization (SEO).AnQiCMS (AnQiCMS) understands this point and therefore provides a powerful and flexible `pagination` tag to help us easily generate professional and user-friendly pagination navigation for website content.We will delve deeper into how to utilize Anqi CMS

2025-11-09