How to retrieve the custom fields (such as author, source, additional parameters) of the current article and display them?

Calendar 78

In AnQi CMS, managing and displaying custom fields for articles such as authors, sources, or additional parameters is a common and practical need in content operation.The AnQi CMS, with its flexible content model design, provides multiple ways to achieve this goal, helping you easily enrich article information and present it to readers in a personalized way.

Understanding the custom fields of Anqi CMS

Firstly, we need to understand how article custom fields work in AnQi CMS.In Anqi CMS, articles, products, and other content all belong to a specific 'content model'.When you create or edit a content model in the background, you can add a series of custom fields to the model.These fields can include single-line text (such as author, source), multi-line text, numbers, single-choice, multiple-choice, or dropdown selections, and other types.

When defining custom fields, you need to set a 'parameter name' (for display in the background) and a 'call field' (for use in templates, usually in lowercase English letters).This 'call field' has become the key to obtaining and displaying custom fields in our template.

Retrieve the custom fields of the current article and display them

The most direct need for the article being viewed is to retrieve its custom fields. Anqi CMS providesarchiveDetailandarchiveParamsTwo template tags are used to achieve this purpose.

Method one: Directly obtain a specific custom field through the field name.

If you know exactly which custom field you want to display (for example, you have defined a custom field namedauthorandsourceas the name of the custom field), you can use it directlyarchiveDetailLabel, and throughnameAttribute specifies the "calling field" of a custom field.

{# 假设您在后台内容模型中定义了调用字段为“author”和“source”的自定义字段 #}
<div>
    <span>作者:</span>{% archiveDetail with name="author" %}
</div>
<div>
    <span>文章来源:</span>{% archiveDetail with name="source" %}
</div>

In this example,{% archiveDetail with name="author" %}Will directly output the current article content:authorThe value of the custom field. If this field may contain HTML content (such as source information from a rich text editor), you may need to add|safeA filter to ensure that HTML is parsed correctly instead of being escaped:

<div>
    <span>文章内容简介(假设是多行文本自定义字段):</span>{% archiveDetail with name="introduction" %}{{introduction|safe}}
</div>

Method two: Loop through all custom fields

If you want to display all the custom parameters of the article, or if you are not sure about the specific custom fields of the article, thenarchiveParamsThe tag will be a good helper. It can retrieve all the custom fields associated with the current article and allow you to display them one by one through a loop.

{# 获取当前文章的所有自定义参数,并以列表形式展示 #}
<div>
    <h5>更多文章参数:</h5>
    {% archiveParams params with sorted=true %}
        {% for item in params %}
            <div>
                <span>{{item.Name}}:</span> {# item.Name 是自定义字段的“参数名”(后台显示名称) #}
                <span>{{item.Value}}</span> {# item.Value 是自定义字段的实际值 #}
            </div>
        {% endfor %}
    {% endarchiveParams %}
</div>

Here, archiveParams paramsStores all custom fields of the current article inparamsthe variable.with sorted=trueEnsure the parametersparamsIs an ordered array for easy useforLoop traversal. In the loop,item.NameIt will display the custom field name (such as "author") that you set in the background, whileitem.Valueit will display the content filled in for the field.

Custom fields are displayed in the article list

The power of custom fields is not limited to the detail page of a single article, but we can also easily retrieve and display them in article lists (such as related articles, category lists). When you usearchiveListTags to loop through and display article lists, each article item is usually asitema variable exists. At this time, you can accessitem.自定义字段的调用字段to obtain and display its custom fields.

{# 假设在一个文章列表循环中,需要显示每篇文章的作者和缩略图 #}
{% archiveList archives with type="list" categoryId="1" limit="5" %}
    {% for item in archives %}
        <div class="article-item">
            <a href="{{item.Link}}">
                <img src="{{item.Thumb}}" alt="{{item.Title}}" />
                <h3>{{item.Title}}</h3>
            </a>
            <p>作者:{{item.Author}}</p> {# 直接访问item.Author,假设Author是自定义字段的调用字段 #}
            <p>发布时间:{{stampToDate(item.CreatedTime, "2006-01-02")}}</p>
        </div>
    {% endfor %}
{% endarchiveList %}

In the above code, we directly through{{item.Author}}Obtained and displayed the author information of each article. The premise is that you have defined the calling field in the content model corresponding to the article asAuthorcustom field.

Summary

AnQi CMS through its flexible content model and intuitive template tags, makes it very simple to retrieve and display custom fields.Whether it is to directly refer to a specific field, traverse all fields, or display in an article list, you can choose the most suitable method according to your specific needs to create a more rich and personalized content page.


Frequently Asked Questions (FAQ)

  1. I define a custom field content that contains HTML code, how to display it correctly on the front end?If your custom field content (for example, a rich text editor input long text) may contain HTML tags, and you want these HTML tags to be parsed by the browser on the front end instead of being displayed as plain text, you need to add|safea filter. For example:{{item.MyCustomHtmlField|safe}}.

  2. How to define custom fields for articles in the background?To define the custom fields of an article, you need to log in to the AnQi CMS backend, navigate to the "Content Management" menu under the "Content Model" module.Find the article content model you want to add fields to (for example, "article model"), click edit.In the model editing page, you can click the 'Add Field' button to define new custom fields for the model, including setting parameter names, called fields, field types, etc.

  3. Can I get custom fields for articles not on the current page?Yes.archiveDetailandarchiveParamsAll tags support throughidThe parameter specifies the article ID. For example, if you want to get the author of the article with ID 10, you can use:{% archiveDetail with name="author" id="10" %}. Similarly,archiveParamsYou can alsoidThe parameter to get all the custom fields of the specified article.

Related articles

How to obtain and display the title, content, thumbnail, and other core information of an article on the article detail page?

When operating a website, the article detail page is the key entry point for users to understand the core value of the content.A well-designed, comprehensive article detail page that not only improves user experience but also effectively helps search engines understand the content of the page, thus optimizing the website's SEO performance.AnQiCMS (AnQiCMS) provides a powerful and flexible template tag system that allows you to easily obtain and present all the core information of the article.

2025-11-08

How to display the article list according to the article views, publish time, or backend custom sorting?

In website operation, the way articles are displayed directly affects user experience and content access efficiency.A well-organized list of articles that can highlight key points, significantly improving user retention and information acquisition efficiency.AnQiCMS as a flexible content management system provides powerful article list display functions, not only can it flexibly filter content, but also can freely adjust the sorting method of articles according to your content strategy, making your website content more attractive.

2025-11-08

How to filter and display a list of articles based on their recommended attributes (such as “Top Article”, “Recommended”)?

In Anqi CMS, efficient content management is one of the keys to website success.Article recommendation attribute, as an important link in the operation of content refinement, it can help us display website content more flexibly, guide users to pay attention to key information, and thus improve the activity and conversion rate of the website.This article will delve into how to filter and display article lists based on the recommended attributes of articles (such as "Headline

2025-11-08

How to display articles under a specific category without including its subcategories?

In website content management, we often encounter such needs: we want to display articles under a specific category on a page, but we don't want to include the sub-category articles under that category to maintain the purity and focus of the content.For example, you may have a "Company News" category that includes subcategories such as "Enterprise Dynamics" and "Industry Information", but on the homepage, you only want to display the pure "Company News" without mixing in the content of all subcategories.

2025-11-08

How to dynamically fetch and display the previous and next articles of the current article on the article detail page?

In website operation, how to allow users to smoothly jump to related or the next article after reading an article is the key to improving user experience and website stickiness.Especially for sites with a large amount of content, such as blogs, information stations, or product display websites, a intuitive 'Previous/Next' navigation function is particularly important.It can not only guide users to deeply browse and reduce the bounce rate, but also provide more internal links for search engines to optimize the SEO performance of the website.AnQiCMS (AnQiCMS) is a powerful content management system that fully considers this need

2025-11-08

How does AnQiCMS define and display related articles? Is it based on keywords or manual association?

In website operation, recommending relevant articles is an important strategy to enhance user experience, extend user stay time, and optimize on-site SEO.AnQiCMS provides a flexible and efficient mechanism to define and display related articles, allowing operators to choose between intelligent recommendations or manual association according to their actual needs. ### Smart Recommendation: Dynamic Association Based on Keywords and Tags The smart recommendation mechanism of AnQiCMS mainly relies on the keywords and tags set in the article content. When you edit articles in the background, you can set: * **Document keywords

2025-11-08

How to retrieve and loop through all document lists under a specific Tag (label) in the template?

In AnQi CMS, content organization can not only be achieved through traditional classification methods, but also flexible "Tag" mechanisms provide a wide space for content association and user search.When you want to display all documents under a specific tag in a certain area of the website, such as the sidebar, related recommendation modules, or even a dedicated Tag aggregation page, AnQi CMS provides a powerful and intuitive template tag that makes this process easy.This article will delve into how to use the Anqi CMS template

2025-11-08

How to retrieve and display detailed information of a specified category, including its description, Banner image, and Logo?

In a content management system, categories are not only the form of content organization, but also the core of website structure and user navigation.Flexibly obtain and display detailed information of a specific category, such as its description, unique banner image and logo, which is crucial for creating attractive and informative pages.AnQiCMS (AnQiCMS) provides an intuitive and powerful template tag to meet this need, allowing you to easily achieve this requirement.### Core Function Tag

2025-11-08