When you manage website content, how to effectively organize and display a document list so that it conforms to user habits and highlights the key points is a very critical link.AnQiCMS provides flexible and powerful features, allowing you to easily implement various sorting and filtering of document content, whether it is by the latest release, most popular, or other customized methods.

In AnqiCMS, flexible display of the document list is mainly achieved through powerfularchiveList

Implement sorting by the latest content

When you want users to see the latest content on the website first, you can usearchiveListlabel'sorderthe parameter and set it toid desc. Here,idIt refers to the unique identifier of the document, which is usually positively correlated with the publication time,descThe content is arranged in descending order, meaning that the content with a higher ID value (usually meaning it was published later) is placed at the front.

For example, if you want to display the latest 10 articles on the homepage or other pages, you can write the template code like this:

{% archiveList archives with type="list" limit="10" order="id desc" %}
    {% for item in archives %}
    <div class="article-item">
        <a href="{{ item.Link }}">{{ item.Title }}</a>
        <span>发布时间: {{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
    </div>
    {% endfor %}
{% endarchiveList %}

Implement sorting by the most popular content

Highlight the most popular or highly viewed content on the website, you canorder="views desc"Parameter to achieve.viewsrepresent the document's page views, set todescAfter, documents with higher views will be displayed first. This is very effective for discovering hot topics or promoting important content.

For example, display the 5 most popular articles:

{% archiveList archives with type="list" limit="5" order="views desc" %}
    {% for item in archives %}
    <div class="hot-article-item">
        <a href="{{ item.Link }}">{{ item.Title }}</a>
        <span>浏览量: {{ item.Views }}</span>
    </div>
    {% endfor %}
{% endarchiveList %}

Implement custom sorting

In addition to the built-in latest and hottest sorting of the system, AnqiCMS also allows you to manually set the display order of documents through the backend. This is usually done byorder="sort desc"To implement.When you manage documents in the background, you can set a 'Display Order' value for each document, and the system will sort according to this value.This is very useful for scenarios that require manual intervention to highlight specific content, such as recommended articles or special topics.

When calling in the template, you can use it like this:

{% archiveList archives with type="list" limit="8" order="sort desc" %}
    {% for item in archives %}
    <div class="featured-article-item">
        <a href="{{ item.Link }}">{{ item.Title }}</a>
    </div>
    {% endfor %}
{% endarchiveList %}

Combine multiple conditions for filtering and sorting

The strength of AnqiCMS lies in the ability to combine these sorting rules with various filtering conditions to create highly customized content lists.archiveListTags support multiple filtering parameters, such as:

  • categoryId: Filter content based on the ID of a specific category.
  • flag: Filter based on the recommended attributes of the document (such as headlines, recommendations, slides, etc.).
  • q: Filter by search keywords.
  • type="page": If you need to display content with pagination, you must set this parameter and combine it withpaginationlabel usage

For example, under a specific category (ID 10), display the latest recommended articles and perform pagination:

{% archiveList archives with type="page" categoryId="10" flag="c" order="id desc" limit="10" %}
    {% for item in archives %}
    <div class="category-recommended-item">
        <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
        <p>{{ item.Description|truncatechars:100 }}</p>
    </div>
    {% empty %}
    <p>该分类下暂无推荐文章。</p>
    {% endfor %}
{% endarchiveList %}

<div class="pagination-container">
    {% pagination pages with show="5" %}
        {# 这里可以放置分页链接的代码,例如:#}
        {% if pages.PrevPage %}<a href="{{ pages.PrevPage.Link }}">上一页</a>{% endif %}
        {% for item in pages.Pages %}<a href="{{ item.Link }}" class="{% if item.IsCurrent %}active{% endif %}">{{ item.Name }}</a>{% endfor %}
        {% if pages.NextPage %}<a href="{{ pages.NextPage.Link }}">下一页</a>{% endif %}
    {% endpagination %}
</div>

exceptarchiveListIf you need a more complex, content model-based custom field filtering feature,archiveFiltersTags can also be useful. They can help you generate filter condition groups, such as filtering by 'type' or 'area' on real estate websites, and then applying sorting on this basis.

Summary

By flexible applicationarchiveListtags and theirorder


Frequently Asked Questions (FAQ)

1. Can I display a list of documents with different sorting rules on the same page?Absolutely, you can. You just need to use multiple templates in the template file.archiveListLabel, and configure different parameters for each labelorderParameters andlimitJust set the parameters. For example, one list displays the latest articles, and another list displays the most popular articles.

2. Besides the latest and the hottest, what other sorting methods are built into AnqiCMS?AnqiCMS supports sorting by document ID in descending order (id descThis usually represents the latest release, sorted by view count in descending orderviews descThis represents the most popular, as well as custom sorting on the backendsort desc)。The value of custom sorting needs to be manually set when editing documents in the AnqiCMS backend.

3. Why didn't the front page take effect immediately after I modified the sorting rules in the template?This is usually due to website caching.In AnqiCMS backend, you can find the "Update Cache" feature, after clicking on Clean Cache, the front page will display the latest sorting effect.Moreover, browser cache may also affect display, it is recommended to clear the website cache as well as the browser cache or access in incognito mode after clearing the website cache.