As a senior CMS website operation personnel of a security company, I am well aware of the importance of obtaining and managing website content, especially for single pages that carry core information such as "About Us", "Contact Information", or "Terms of Service".In Anqi CMS, the system provides an efficient and flexible way to obtain the list of these single pages, so that we can integrate it into the website navigation, site map, or other places that need to be displayed.

Understand the single-page in Anqi CMS

The single-page feature of AnQi CMS is designed to manage static content that exists independently and does not belong to any article or product category.These pages typically have a fixed structure and specific purposes, such as company introduction, privacy policy, disclaimer, etc.In website operation, we often need to link these single-page links to the header, footer, or sidebar of the website to ensure that users can easily find and access this important information.Understand how to programmatically obtain the list of these pages, which is the basis for meeting these requirements.

UsepageListTag to get the list of single-page lists

Anqi CMS provides a namedpageListThe template tag, specially designed to retrieve all single-page data on a website. This tag is very concise and efficient, requiring no complex parameter configuration to meet most scenarios.

To usepageListLabel, you can write the template code like this:

{% pageList pages %}
    {# 循环输出单页面数据 #}
{% endpageList %}

Here, pagesIs a custom variable name that will carry frompageListThe label gets all the single page data, this variable is an array (or list) object. You can also choose any other meaningful variable name.{% pageList pages %}and{% endpageList %}The tag pair will enclose the logic you want to process for each single page.

Traverse and display single page data

due topagesThe variable is an array containing multiple single page objects, and we need to useforLoop the tag to iterate over it and extract the details of each single page one by one. Inside the loop, each single page object is usually nameditemOf course, you can also customize this variable name.

EachitemObjects contain a series of available fields that can provide key information on a single page, such as:

  • IdThe unique identifier of the single page.
  • TitleThe title of the single page, usually displayed on the website.
  • LinkThe access link of the single page.
  • DescriptionThe brief description of the single page.
  • ContentThe detailed content of the single page.
  • Logo: The main image or large image of a single page.
  • Thumb: The thumbnail of a single page.

You can select and display these fields according to your actual needs. For example, to create a simple single-page navigation list, you can do it like this:

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

This code will generate an unordered list where each list item is a link to a single page, and the link text is the title of the single page.

Filter and customize the display of single pages

In practice, we may not want all single pages to be displayed in the same list.The AnQi CMS template engine provides flexible control structures, allowing us to filter or customize the display of a single page based on specific conditions.

For example, if you want to exclude a specific ID single page (such as the 'About Us' page with ID 1, as it may already be fixed in the main navigation), you canforAdd within the loopifConditional judgment:

<ul>
{% pageList pages %}
    {% for item in pages %}
    {% if item.Id != 1 %} {# 排除ID为1的单页面 #}
    <li>
        <a href="{{ item.Link }}">{{ item.Title }}</a>
    </li>
    {% endif %}
    {% endfor %}
{% endpageList %}
</ul>

This method allows us to finely control which single pages appear in the list, thereby meeting different design and operational needs.In addition, if you want to display a thumbnail or description on a single page, just refer to the corresponding field within the loop.

Suitable for multi-site environments

AnQi CMS supports multi-site management,pageListThe label also takes this into account. If you have created multiple sites in the background and need to call single-page data from different sites, you can specify thesiteIdparameter.

{% pageList pages with siteId="2" %} {# 获取ID为2的站点的单页面列表 #}
    {% for item in pages %}
    <li>
        <a href="{{ item.Link }}">{{ item.Title }}</a>
    </li>
    {% endfor %}
{% endpageList %}

However, in most single-site operation scenarios, it is usually not necessary to specify manuallysiteIdbecausepageListthe tag will default to retrieving the single-page data of the current site

background management and template association

In the AnQi CMS backend, the single page management is located under the "Page Resources" section in the "Page Management" module. Here, you can create, edit, and delete single pages, and set the title, content, URL alias for each single page, and even specify independent template files (such aspage/detail.htmlorpage/about.html)。These backend settings directly affect the frontendpageListThe data and display effects that the tag can obtain. For example, if you have customized a URL alias for a single page, thenitem.LinkIt will reflect this custom URL.

By making reasonable use ofpageListThe tag and its rich fields allow you to easily build dynamic single-page lists in Anqi CMS, whether for website navigation, information display, or internal management, it provides great convenience and flexibility.


Frequently Asked Questions (FAQ)

1. I want to display all my single pages in the navigation, but I don't want users to see the single page of the "old contact information". What should I do?

You can usepageListLabel after obtaining all single-page list items, within the loop throughifConditional judgment to exclude pages that you do not want to display. For example, if the title of the "Old Contact Information" page is "Old Contact Information", you can write the code like this:

<ul>
{% pageList pages %}
    {% for item in pages %}
    {% if item.Title != "旧版联系方式" %}
    <li>
        <a href="{{ item.Link }}">{{ item.Title }}</a>
    </li>
    {% endif %}
    {% endfor %}
{% endpageList %}
</ul>

Or, if you know the ID of the single page, useitem.Id != [您的页面ID]Excluding it will be more accurate.

2. Where is the default single-page template file of AnQi CMS, and how can I specify a unique template for a specific single page?

The single-page default template of AnQi CMS is usually stored in the theme directory you are currently using.page/detail.htmlFile. If you need to specify a unique template for a single page, you can create a new template file in the template directory, for examplepage/about.htmlThen edit the single page in the background "Page Management", fill in the "Single Page Template" settingsabout.htmlThe system will prioritize the custom template you specify to render the single page.

How to get the single page list of other sites (in multi-site mode)?

If you have enabled the multi-site feature of Anqi CMS and need to get the single page list of non-current sites, you canpageListthe tag withsiteIdParameters. For example, if you want to get a single-page list of site ID 2, you can use the tag like this:{% pageList pages with siteId="2" %}...{% endpageList %}Make sure you know the correct ID of the target site, which is usually visible in the "Multi-site Management" section of the backend.