How to skip a specific `Id` page and not display it when looping through a single page `tag-pageList`?

Calendar 👁️ 61

Skillfully control content display: AnQi CMStag-pageListSkip a specific page in the loop

As an experienced website operations expert, I fully understand that the flexibility of a content management system is crucial for operational efficiency and user experience.AnQiCMS (AnQiCMS) provides us with powerful content management capabilities with its high-performance architecture based on the Go language.In daily operations, we often encounter scenarios where we need to fine-tune content control, such as skipping or not displaying certain pages in a page list loop.tag-pageListHow to cleverly skip a specific page when displaying single page content in a loopIdto meet the demand of diversified content presentation.

Why do we need to skip a specific page?

In AnQi CMS,pageListLabels can conveniently list the "single-page" content created on our backend (such as "About UsThese single pages are crucial for the basic information construction of the website, but they are not suitable for full display in all scenarios.

For example, you might have a 'All Pages' navigation menu, where you want to list most of the general single-page, but some special, internally used, or pages that you do not want users to access directly through the list (such as a test page, a temporary event page, or a legal statement page that can only be accessed through a specific entry) should not appear in this list. At this point, ifpageListThe tag does not provide a direct 'exclude ID' parameter, so we need to rely on the strong logical control capabilities of the AnQiCMS template engine to achieve this goal.

AnQiCMS's solution: conditional judgment within the loop

AnQiCMS template engine supports Django template syntax, which means we can iterate over the looppageListUtilize the data obtainedifScreen and exclude pages that do not meet our requirements using conditional judgment tags. This method provides an extremely flexible and powerful content control mechanism.

First, let's reviewpageListThe basic usage of the tag. It retrieves all the single page content from the background and encapsulates it into an array object that can be traversed.

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

This code will list all single-page titles and links. Now, suppose we want to skipIdWith1the "About Us" page, as well asIdWith5The "Privacy Policy" page, do not let them appear in this list. We can useforinside the loop, usingifconditional judgment tags and pagesitemthe object'sIdattributes to achieve this.

item.IdIs AnQiCMS automatically generated unique identifier for each single page. We can compare thisIdto decide whether to display the current page in the loop.

In order to make the template output cleaner, we can also make good use of{%-and-{%This 'remove logical tag line' format, it will intelligently remove the leading and trailing white spaces before and after the tag, making the generated HTML code more compact.

Example of skipping a single specific page:

If we only want to skipIdWith1the page, the code can be written as:

<ul>
{% pageList pages %}
    {% for item in pages %}
        {%- if item.Id != 1 %}
        <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
        {%- endif %}
    {% endfor %}
{% endpageList %}
</ul>

In this example,{%- if item.Id != 1 %}It will check the current pageitemofIdwhether it is not equal to1. Only when the condition is true,<li>Tags and the page titles and links they contain will be rendered and output.

Example of skipping multiple specific pages:

If you need to skip multiple non-continuous pages, for exampleIdWith1and5The page, where we can use logical operatorsandTo connect multiple conditions:

<ul>
{% pageList pages %}
    {% for item in pages %}
        {%- if item.Id != 1 and item.Id != 5 %}
        <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
        {%- endif %}
    {% endfor %}
{% endpageList %}
</ul>

So, only whenitem.IdNot equal to1Nor equal to5The page will be displayed.

A more flexible exclusion method: usecontainFilter out the IDs from the exclusion list

Use it when there are many page IDs to exclude.and item.Id != XThe way might make the code look long. AnQiCMS providescontainfilter, combinedlistA filter that can handle this situation more elegantly. We can first define a listIdcontaining all the IDs to be excluded, and then judge whether the current page is in this list.

{% set excluded_ids = '[1, 5, 8, 12]'|list %} {# 定义一个包含要排除ID的列表 #}
<ul>
{% pageList pages %}
    {% for item in pages %}
        {# 检查当前页面ID是否不在排除列表中 #}
        {%- if not (excluded_ids|contain:item.Id) %}
        <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
        {%- endif %}
    {% endfor %}
{% endpageList %}
</ul>

In this more advanced example, we first use{% set excluded_ids = '[1, 5, 8, 12]'|list %}Defined a namedexcluded_idsan array that contains all the page IDs we want to skip. Then, inside the loop,not (excluded_ids|contain:item.Id)this line of code judgesitem.Idwhether it existsexcluded_idsIf in the list.item.IdNotIn this list, the current page will be displayed normally. This method can significantly improve the clarity and maintainability of the template code when there are a large number of IDs to exclude.

Application scenarios and **practice

This kind ofpageListMethod of skipping specific pages through conditional judgment in a loop, which has a wide application in actual operation:

  • Simplify navigation and content aggregation:On the footer, sidebar, or some special topic page of the website, you may only need to display some selected or important single pages, rather than showing all pages, to keep the interface clean and focus on the user.
  • A/B testing or temporary activity page:For some single pages that are undergoing A/B testing or temporary promotion, you may not want them to appear in the regular page list to avoid disturbing the test results or prematurely revealing information.
  • Internal Management or Draft Page:The website backend may have some draft pages that are not yet completed, or management pages that are only for internal staff viewing, these pages must never appear in any public-facing list.
  • SEO optimization:Some single-page content may have a lower value or contain duplicate content, which is not suitable for extensive indexing by search engines. By excluding it from the list, it can be prevented from being exposed in sitemaps or other aggregation pages, thereby more effectively controlling the search engine crawling.

By flexibly using the conditional judgment capability of the AnQiCMS template engine, you can control the website

Related articles

How to use `if` judgment in AnQiCMS template to prevent rendering errors caused by undefined variables?

## Mastering AnQi CMS Template: Skillfully use `if` statements to say goodbye to undefined variable rendering errors!As a senior website operation expert, I am well aware of the importance of a stable and efficient website template for user experience and operation efficiency.AnQiCMS (AnQiCMS) offers powerful support for content management with its efficient architecture based on the Go language and a flexible Django-like template engine.However, even the most excellent system may cause rendering errors due to minor omissions in the template, the most common of which is accessing undefined variables. Today

2025-11-06

How to conditionally generate a URL based on the settings of `BaseUrl` or `MobileUrl` in the `tag-system` tag?

## Precise Targeting: How to generate URL based on `BaseUrl` or `MobileUrl` conditions in AnQi CMS?In today's multi-screen interconnected era, providing users with smooth and device-adaptive content experience is the key to the success of website operation.Whether it is on the PC side or the mobile side, we hope that users can access the page that is most suitable for their device.AnQi CMS, this enterprise-level content management system developed based on the Go language, with its efficient and flexible features, provides powerful tools for content operators to meet this challenge.Today, as an experienced website operation expert

2025-11-06

How to determine the relationship between the current time and the document publishing time in the AnQiCMS template, and display "New" or "Expired"?

## Content时效性:How to intelligently display “New Release” and “Expired” in AnQiCMS template In the ever-changing world of the Internet, the 'freshness' and 'timeliness' of content are key to attracting and retaining visitors on the website.As an experienced website operation expert, I am well aware of the powerful features of AnQiCMS (AnQi Content Management System), which not only provides flexible content management capabilities but also endows content with infinite display possibilities through its powerful template engine.Today, we will delve into how to use the AnQiCMS template

2025-11-06

How to conditionally use the `cycle` tag to alternate CSS classes within a `for` loop?

## How to conditionally use the `cycle` tag elegantly in the `for` loop of AnQiCMS?In website content display, especially on list pages, we often hope to enhance user experience and information readability through visual differences.For example, list rows alternate with different background colors, or certain types of list items require special styles to highlight.As an experienced website operations expert, I am well aware of the efficient and flexible content management system in AnQiCMS

2025-11-06

In AnQiCMS template, how to determine if the date format converted by `stampToDate` is correct or valid?

In the vast realm of content management and website operation, every detail concerns the user experience and the accuracy of information transmission.The accurate display of date and time is an indispensable part of it.For operators and developers using AnQiCMS to build websites, how to elegantly handle timestamps in templates and ensure their correct and effective format is a topic worth in-depth discussion.Today, let's talk about the philosophy and practical wisdom of using the `stampToDate` tag in the AnQiCMS template.### Know

2025-11-06

How is Json-LD structured data automatically generated in AnQiCMS?

In today's highly competitive online environment, the SEO performance of a website is crucial, and structured data is one of the key technologies to enhance the visibility of a website in search results.As a system dedicated to providing an efficient and easy-to-use content management solution, AnQiCMS deeply understands the importance of structured data in improving website visibility.It not only provides users with convenient content publishing and management tools, but also quietly contributes to the SEO optimization of the website behind the scenes.

2025-11-06

How to manually enable or disable the Json-LD structured data feature of the AnQiCMS website?

## Unlock AnQiCMS website SEO tool: How to enable and customize Json-LD structured data As an experienced website operation expert, I am well aware that in today's fiercely competitive content ecosystem, it is crucial to know how to make a website stand out in search engines.AnQiCMS (AnQiCMS) provides us with a solid technical foundation with its lightweight, efficient, and SEO-friendly features.Among them, the Json-LD structured data feature is a powerful tool to enhance the visibility and attractiveness of a website.

2025-11-06

The Json-LD custom call tag `{% Ld %}` should be placed at which position in the template?

In AnQi CMS, where should the Json-LD custom call tag `{% Ld %}` be placed in the template?In today's digital marketing era, the importance of Search Engine Optimization (SEO) is self-evident.And structured data, especially Json-LD, is one of the powerful tools to improve the visibility of websites in search results.AnQi CMS is an efficient system designed for enterprise-level content management and SEO optimization, naturally providing comprehensive Json-LD support.

2025-11-06