Managing and displaying single-page content in AnQiCMS is a common requirement for website operations, especially for static content such as 'About Us', 'Contact Information', and 'Terms of Service'.As an experienced AnQiCMS operations personnel, I know 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.

Understand the single page mechanism in AnQiCMS

In AnQiCMS, Single Page is a special page type independent of content models such as articles and products.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 retrieve and display all single pages created on the website, we need to use the built-in AnQiCMS.pageListLabel. This label will return an array object containing all the single page data, and we can iterate over this array to display the information of each single page one by one.

Generally,pageListThe usage of tags is as follows, among whichpagesis the variable name defined for the single page list 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,itemrepresents a single page variable in each iteration. We can accessitemThe attribute to retrieve detailed information of a single page, for example:

  • item.Id: Unique ID of the single page.
  • item.Title: Single page title.
  • item.LinkThe access link of the single page.
  • item.Description: Brief introduction of the single page.
  • item.Content: Full content of a single page.
  • item.Logo: Large image of a single page (if set).
  • item.Thumb: Thumbnail of a single page (if set).

This method is very suitable for displaying all single-page links uniformly at the bottom of a website, in the sidebar, or on some aggregation page.

List single pages of specified type

In some cases, we may need to control the display of a single page more precisely, for example, to only display the "About Us" page, or to exclude a specific page. AnQiCMS combinespageDetailTags andforLooping conditions provide us with this flexibility.

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

If we clearly know the ID or URL alias of a single pagetoken), you can use it directlypageDetailtag to retrieve its details. This is very useful when you need to embed the content of a specific single page into another page.

for example, get the ID of1Single page title:

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

Or through a URL aliasabout-usGet its content:

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

This method is direct and efficient, suitable for single page calls with fixed and unique content.

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

When we usepageListAfter obtaining all single-page items, you canforLoop addedifmake conditional judgments based on the single-pageId/TitleorLinkUse properties to filter out the pages we want or exclude the ones we don't want.

For example, to list all single pages but exclude pages with ID as1The "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>

Again, we only want to display a single page whose title contains the word 'service':

<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 should be noted that,item.Title contains "服务"This advanced string matching may require combining with the filters provided by the AnQiCMS template engine (such asfilter__name:paramOr Go languagestrings.ContainsFunction (if the template engine supports it). In AnQiCMS's Django template syntax, it is usually usedifThe 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 completely feasible.

3. Use Custom URL Aliases and Custom Templates

AnQiCMS allows setting a "custom URL" and a "single-page template" for single pages. This means we can assign a business-related URL alias to a single page through backend configuration, such asabout-usCorresponding to the "About Us" page), and call it through this alias in the template. Furthermore, if certain single pages require a completely unique layout, they can be assigned exclusive template files (such aspage/about.html), so that the system will automatically load the corresponding custom template when accessing these pages.This approach is not directly used for list filtering, but provides the ability to highly customize the display of a specific single page.

Template file organization and rendering

According to the AnQiCMS template convention, 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 accurately call and display single page content across different pages.

The AnQiCMS 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 using combinationspageListandpageDetailTags, as well as appropriate template logic judgment to implement. This allows website operators to easily meet various content display needs, ensuring high-quality presentation of website content.


Frequently Asked Questions (FAQ)

1. Why do I usepageListThe label does not display any single page content?

IfpageListThe label does not display any content, please first check whether a single page has been created in the 'Page Management' of AnQiCMS backend.Make sure these pages are in the "Published" status, not in drafts or the recycling bin.Secondly, check if the path to your template file is correct, as well as whether the syntax of the tags conforms to the AnQiCMS Django template engine specifications.

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

InpageListIn the loop, eachitemAll variables includeThumbfield used to store the thumbnail address of a single page. You can<li>add a<img>Label, andsrcset the attribute to{{item.Thumb}}to display the thumbnail. It is best to use it before addingif item.ThumbMake a judgment to avoid breaking images when there are no thumbnails.

3. How can I make some single-page websites not be indexed by search engines?

For single pages that you do not want to be indexed by search engines, you can find the SEO-related settings in the AnQiCMS back-end when editing the single page, which usually includes options such as "nofollow" or "noindex". If you call it directly in the template and the page does not generate a separate URL (such as just embedded content), you may consider in<a>the tag withrel="nofollow"Attribute, or on the pageheadPartially add<meta name="robots" content="noindex, nofollow">Tag, which is usually achieved through custom templates or usingtdkThe SEO field of the tag can be realized. AnQiCMS mentioned the TDK settings, includingtag-tdk.mdThe document mentioned the TDK settings, includingCanonicalUrl,Indirectly supports SEO control, you can also set SEO titles, keywords, and descriptions for specific pages in the background, and use these fields to generatemeta.