In AnQiCMS, managing and displaying single pages is a common requirement for website operations, especially for static content such as "About UsAs an experienced AnQiCMS operation staff, I am well aware that efficient use of template tags can greatly enhance the flexibility of content publishing and the maintenance efficiency of the website.This article will detail how to list all or specified types of single pages in the AnQiCMS template.

Understanding the single page mechanism in AnQiCMS

In AnQiCMS, Single Page is a special page type that is independent of content models such as articles, products, etc.They are usually used to display relatively fixed content that does not involve classification or list aggregation.AnQiCMS provides a dedicated "Page Management" feature (located under "Page Resources") to create and edit these single pages.On the template level, AnQiCMS provides intuitive and powerful tags for single-page calls.

List all single pages

To obtain and display all single pages created on the website, we need to use the built-in AnQiCMSpageList标签。This tag returns an array object containing all single-page data, and we can iterate through this array to display each single-page information one by one.

Usually,pageListThe usage of labels is as follows, wherepagesis the variable name defined for the single-page list we have obtained:

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

In the above code,itemis the variable representing a single page in each loop. We can access it byitemThe attribute to retrieve detailed information of a single page, for example:

  • item.IdUnique ID of a single page.
  • item.Title: Title of the single page.
  • item.LinkPage access link.
  • item.DescriptionSummary of a single page.
  • item.Content: Full content of the single page.
  • item.Logo: Large image of the single page (if set).
  • item.Thumb:Single-page thumbnail (if set).

This method is very suitable for the scenario where all single-page links are displayed uniformly at the bottom of the website, in the sidebar, or on a certain aggregation page.

List the specified type of single-page

In some cases, we may need to control the single page to be displayed more precisely, for example, only displaying the "About Us" page, or excluding a specific page. AnQiCMS combinespageDetailTags andforLoop conditions provide this kind of flexibility.

1. Get the single page details of the specified ID or URL alias

If we explicitly know the ID or URL alias of a single pagetoken), you can use it directly,pageDetailtags to get its details. This is very useful when you need to embed specific single page content into other pages.

For example, to get the title of1the single-page:

<div>关于我们页面标题:{% pageDetail with name="Title" id="1" %}</div>

Or through the URL alias:about-usTo get the content:

{% pageDetail aboutPage with name="Content" token="about-us" %}
<div>关于我们页面内容:{{aboutPage|safe}}</div>

This method is direct and efficient, suitable for calling single-page content that is fixed and unique.

2. Exclude or select specific pages in all single-page lists

When we usepageListAfter obtaining all single-page pages, you canforto display a friendly prompt when no matching document is found.ifConditional judgment, based on the single-page pagesId/TitleorLinkUse properties such as filtering out the pages we want, or excluding pages we don't want.

For example, to list all single pages but exclude the page with ID.1The "About Us" page:

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

又如,我们只想显示标题中包含“服务”二字的单页面:

<ul>
{% pageList pages %}
    {% for item in pages %}
        {% if item.Title contains "服务" %} {# 假设存在“contains”过滤器或使用其他逻辑 #}
        <li>
            <a href="{{ item.Link }}">{{item.Title}}</a>
            <p>{{item.Description}}</p>
        </li>
        {% endif %}
    {% endfor %}
{% endpageList %}
</ul>

It is worth noting that,item.Title contains "服务"这类高级字符串匹配可能需要结合AnQiCMS模板引擎提供的过滤器(如filter__name:param)or Go languagestrings.Containsfunction (if the template engine supports it).In AnQiCMS's Django template syntax, it is usually usedifThe direct comparison of statements combined with variables, or with the help of preprocessed data. If it is simply a match of ID or alias, the aforementioneditem.Id != 1method is perfectly feasible.

3. Using custom URL aliases and custom templates

AnQiCMS allows setting a "custom URL" and "single page template" for a single page. This means that we can assign a business-related URL alias to a single page through backend configuration (for exampleabout-uscorresponding to the "About Us" page), and call it through this alias in the template. Furthermore, if some single-page needs a completely unique layout, a dedicated template file can be specified for them (for example,page/about.html),so that the system will automatically load the corresponding custom template when accessing these pages.This method is not directly used for list filtering, but provides the ability to customize the height of a specific single-page display.

Template file organization and rendering

According to the template conventions of AnQiCMS, the default template for a single page detail page ispage/detail.html. If a custom template is specified for a single page, for example namedpage/about.htmlThen, when accessing the single page, it will renderabout.htmlUnderstanding these rules helps us organize template files more effectively and call and display single page content accurately across different pages.

AnQiCMS's single-page management mechanism is flexible and powerful, whether it is to list all single pages uniformly, or to call or filter specific pages accurately, it can be achieved by combining usagepageListandpageDetailTags, as well as appropriate template logic judgment to implement. This allows website operators to easily meet various content display needs, ensuring the high-quality presentation of website content.


Common Questions and Answers (FAQ)

1. Why do I only show a few tags instead of all the tags I expected after using the tag?pageListLabel does not display any single page content?

IfpageListThe label does not display any content, please check first whether the single page has been created in the 'Page Management' section of the AnQiCMS backend.Ensure these pages are in the "Published" status, rather than drafts or the trash.Firstly, check if the path of your template file is correct, and whether the syntax of the tags completely conforms to the Django template engine specification of AnQiCMS.

2. How to display thumbnails next to each item in the single page list?

InpageListin the loop, eachitemAll variables are includedThumbField, used to store the thumbnail address of a single page. You can<li>add a<img>tags, andsrcproperty is set to{{item.Thumb}}to display the thumbnail. It is best to use it before addingif item.ThumbPerform a judgment to avoid broken images from appearing when there is no thumbnail.

3. I want some single pages not to be indexed by search engines. How should I do it?

For single pages that you do not want to be indexed by search engines, you can find SEO-related settings when editing the single page in the AnQiCMS backend. There are usually options like "nofollow" or "noindex". If you call it directly in the template and the page does not generate a separate URL (for example, it is just embedded content), then you can consider<a>tag.rel="nofollow"属性,或者在页面headsome additions<meta name="robots" content="noindex, nofollow">标签,这通常通过自定义模板或使用tdk标签的SEO字段来实现。AnQiCMS的tag-tdk.md文档提到了TDK设置,包括CanonicalUrlIndirectly supports SEO control, you can also set SEO titles, keywords, and descriptions for specific pages in the background, and use these fields to generatemetaLabel.