How to get and display the detailed information of a single article in AnQiCMS?

Calendar 👁️ 72

In AnQiCMS, managing and displaying content is one of its core functions.It is crucial to understand how to accurately obtain and display detailed information about a specific article when you need to present it to visitors.AnQiCMS provides a直观 and powerful template tag system that allows you to flexibly control the layout and content of article detail pages.

AnQiCMS template system overview

AnQiCMS templates use a syntax similar to the Django template engine. In the template files, you will encounter two main tags:

  • double curly braces{{ 变量 }}: is used to output the value of a variable.
  • single curly braces and percent signs{% 标签 %}Used to control the logic flow (such as conditional judgments, loops) or to call specific function tags.

Generally, the detail page template file of a single article follows certain naming conventions, such as being stored in{模型table}/detail.htmlsuch a path. For example, if your article belongs to the "article model", then the detail page template may bearticle/detail.html.

to get the core information of a single article:archiveDetailTag

To obtain and display the detailed information of a single article, AnQiCMS provides a specialarchiveDetailtag. This tag is the foundation for building the article detail page.

archiveDetailusage

When you use the template on the article detail pagearchiveDetailthe tag will default to retrieving the article data on the current page. You just need to specify the field name you want to retrieve.

For example, to display the article title, you can write it like this:

<h1>{% archiveDetail with name="Title" %}</h1>

here,name="Title"Tell the system what article title you want to get. Similarly, you can get other commonly used fields:

  • Article content (Content)The main content of the article, usually containing HTML format. To ensure that the HTML content is rendered correctly rather than displayed as plain text, you need to use|safeFilter. If the article content uses a Markdown editor in the background, AnQiCMS will also automatically render it as HTML, but you can also userender=trueParameter forced rendering, orrender=falseTo cancel rendering.
    
    <div>{% archiveDetail archiveContent with name="Content" %}{{ archiveContent|safe }}</div>
    
  • Article description (Description): It is usually the abstract or introduction of the article.
    
    <p>{% archiveDetail with name="Description" %}</p>
    
  • Article link (Link): Article access address.
    
    <a href="{% archiveDetail with name="Link" %}">查看原文</a>
    
  • Article thumbnail (LogoorThumb): The cover image or thumbnail of the article.
    
    <img src="{% archiveDetail with name="Logo" %}" alt="{% archiveDetail with name="Title" %}" />
    
  • Publish time (CreatedTime): AnQiCMS stores timestamps, you need to usestampToDatea function to format it into a readable date and time.
    
    <span>发布日期:{{ stampToDate(archive.CreatedTime, "2006-01-02 15:04") }}</span>
    
  • Views (Views)The number of times the article has been accessed.
    
    <span>阅读量:{% archiveDetail with name="Views" %}</span>
    
  • Article ID (Id) and the category ID (CategoryId)These are the unique identifiers and category identifiers of the articles, often used to obtain associated information further.
    
    <span>文章ID:{% archiveDetail with name="Id" %}</span>
    

指定特定文章

If you are not on the article detail page or need to get the details of other articles, you canidortokento specify the parameters:

{# 获取ID为10的文章标题 #}
<h2>{% archiveDetail with name="Title" id="10" %}</h2>
{# 获取URL别名为"my-first-article"的文章内容 #}
<div>{% archiveDetail with name="Content" token="my-first-article" %}{{archiveContent|safe}}</div>

Gain in-depth information about the related articles

An individual article is often not just its own content, but is closely related to categories, tags, custom attributes, and other information.The AnQiCMS template system allows you to easily retrieve this related data.

Get the detailed information of the article category

archiveDetailTags can be retrieved althoughCategoryIdIt only provides IDs. To get the category name and link, we need to combinecategoryDetail.

{# 先获取当前文章的完整对象(通常在详情页中,直接用`archive`变量即可,或者通过archiveDetail获取) #}
{% archiveDetail currentArchive with name="Id" %} {# 确保有archive对象,或先获取 #}
<p>所属分类:<a href="{% categoryDetail with name='Link' id=archive.CategoryId %}">{% categoryDetail with name='Title' id=archive.CategoryId %}</a></p>

here,id=archive.CategoryIdWill pass the category ID of the current article tocategoryDetailthe tag, so as to obtain the name and link of the category.

Get the tag list of the article

If your article has multiple tags set, you can usetagListLabels to display them.

<div class="article-tags">
    <strong>标签:</strong>
    {% tagList tags with itemId=archive.Id %}
        {% for tag in tags %}
            <a href="{{ tag.Link }}">{{ tag.Title }}</a>
        {% endfor %}
    {% endtagList %}
</div>

itemId=archive.IdEnsure the parameterstagListThe ones obtained are related tags of the current article.

Display the custom parameters of the article.

AnQiCMS allows you to add custom fields to the article model. These fields can be accessed viaarchiveParamstags, or directly througharchiveDetailSpecify the tagnameParameter to obtain.

{# 遍历显示所有自定义参数 #}
<div class="article-params">
    {% archiveParams params %}
        {% for item in params %}
            <p>{{ item.Name }}:{{ item.Value }}</p>
        {% endfor %}
    {% endarchiveParams %}
</div>

{# 如果您知道自定义字段的名称,可以直接获取,例如一个名为“author”的字段 #}
<p>作者:{% archiveDetail with name="author" %}</p>

the previous and next articles

At the bottom of the article detail page, links to the 'previous article' and 'next article' are usually displayed, convenient for users to browse.

<div class="navigation-links">
    {% prevArchive prev %}
        {% if prev %}
            <a href="{{ prev.Link }}">上一篇:{{ prev.Title }}</a>
        {% else %}
            <span>上一篇:没有了</span>
        {% endif %}
    {% endprevArchive %}

    {% nextArchive next %}
        {% if next %}
            <a href="{{ next.Link }}">下一篇:{{ next.Title }}</a>
        {% else %}
            <span>下一篇:没有了</span>
        {% endif %}
    {% endnextArchive %}
</div>

Get the SEO information of the page

of the article detail page's<head>The area needs to set appropriate SEO titles, keywords, and descriptions.tdkTags can help you dynamically retrieve this information.

<head>
    <title>{% tdk with name="Title" siteName=true %}</title>
    <meta name="keywords" content="{% tdk with name="Keywords" %}">
    <meta name="description" content="{% tdk with name="Description" %}">
</head>

siteName=trueThe parameter will be automatically appended to the article title, improving SEO friendliness.

Comprehensive example: Build a basic article detail page.

Here is an example of an integrated article detail page template that you can adjust and beautify according to your needs:

`twig {% extends ‘base.html’ %} {# inherit the base template, usually containing header, footer, etc. #}

{% block head_meta %}

{# 动态设置页面SEO信息 #}
<title>{% tdk with name="Title" siteName=true %}</title>
<meta name="keywords" content="{% tdk with name="Keywords" %}">
<meta name="description" content="{% tdk with name="Description" %}">
{# 规范链接 #}
{% tdk canonical with name="CanonicalUrl" %}
{% if canonical %}<link rel="canonical" href="{{canonical}}" />{% endif %}

{% endblock %}

{% block main_content %} <

Related articles

How to display all documents under the current category and its subcategories in AnQiCMS template?

In AnQiCMS template design, flexibly displaying content is the key to website operation.When you need to display articles under a category page not only, but also hope to present all subcategory articles together, or display them in a more structured way, AnQiCMS provides powerful template tags to meet these needs.This article will introduce in detail how to implement this feature in your AnQiCMS template.### Understanding AnQiCMS's classification and document mechanism In AnQiCMS, content is usually organized under "document model" and "classification"

2025-11-08

How to filter and display a list of documents in AnQiCMS using custom parameters?

In AnQiCMS (AnQiCMS), when managing and displaying a large amount of content, we often need to go beyond simple categories and tags to achieve more refined content filtering.For example, a real estate website may need to filter listings by "type", "area", and "price range";An e-commerce website may need to filter products by color, size, and brand.AnQiCMS provides a powerful custom parameter feature, making it very intuitive and efficient to implement this advanced filtering.Below, we will gradually understand how to use AnQiCMS

2025-11-08

How to display a list of articles published by a specific author in AnQiCMS?

In AnQiCMS, efficiently managing and displaying content is the core of website operation.Sometimes, you may need to display all the articles published by a specific author, such as creating an author column, a team member introduction page, or a personal portfolio.AnQiCMS's powerful template tag system provides a flexible way to meet this requirement, allowing you to easily filter and display a list of content from specific authors.This article will introduce you to how to display a list of articles published by a specific author in AnQiCMS, helping you better organize your website content.##

2025-11-08

How can articles be sorted by views in the AnQiCMS template?

In AnQiCMS, content management is not limited to publishing and organizing, how to effectively display these contents, especially placing popular articles in prominent positions, is the key to improving user experience and website activity.This article will introduce in detail how to sort the article list by views in the AnQiCMS template, making hot content naturally stand out.

2025-11-08

How to call and display custom field content in the article detail page of AnQiCMS?

In AnQiCMS, managing and displaying content, custom fields play a crucial role, enabling our website to flexibly carry various unique information, not limited to common attributes such as titles and content.Whether it is to add detailed technical parameters for product detail pages or to supplement author biographies and external reference links for articles, custom fields can provide strong support.Understand how to call and display these custom fields on the article detail page, which will greatly enhance the richness and customization of the website content. AnQiCMS

2025-11-08

How to display the links and titles of the previous and next articles on the article detail page?

When a reader visits an article of interest, they often hope to browse related or continuous content seamlessly, rather than returning to the list page to search again.Provide navigation links to "Previous" and "Next" articles on the article detail page of the website, which is an effective way to enhance this reading experience and increase user stickiness.It can not only guide users to explore the website content in depth, but also optimize the internal link structure of the website to a certain extent, making it friendly to search engines.AnQiCMS (AnQiCMS) is a powerful content management system that fully considers the needs of content operation

2025-11-08

How does AnQiCMS implement intelligent recommendation and display of related articles?

In content operation, effectively recommending relevant articles to readers can not only significantly increase user stay time and page views, but also indirectly promote search engines to crawl and allocate weights to the website's content through internal link optimization.AnQi CMS is well-versed in this, providing a smart and flexible mechanism to help users easily implement the recommendation and display of related articles.How does AnQiCMS implement intelligent article recommendation?

2025-11-08

How to display the publish time and update time of articles in AnQiCMS templates?

Understand the publication and update time of an article, which not only helps readers judge the timeliness of the content and avoid outdated information, but also is an important consideration for search engine optimization (SEO).AnQiCMS as an efficient content management system provides flexible template functions, allowing you to easily display these key time information on your website.

2025-11-08