In Anqi CMS, managing and displaying content, the article detail page is undoubtedly the core battlefield for users to obtain information.In addition to the basic elements such as the article title and content, we often need to display some personalized information on the detail page, such as the author of the article, the source of the content, product specifications, and the place of publication, etc.This information is called "Custom Parameters" in AnQi CMS, which can greatly enrich the dimensions of content and meet the personalized needs of different business scenarios.
The AnQi CMS provides a very flexible way to define and display these custom parameters, allowing website operators to easily customize the content display of article detail pages.Below, let's take a look together at how to operate so that these custom parameters can be presented elegantly on the article detail page.
Step 1: Define your custom parameters in the background
In AnQi CMS, custom parameters are defined through the 'Content Model'.The content model is like the skeleton of content, which determines what fields a type of content (such as "article" or "product") can have.
- Enter content model managementFirst, log in to your Anqi CMS admin interface, navigate to the "Content Management" menu, find the "Content Model" option and click to enter.
- Select or create a new model.:Generally, you may already be using the system's built-in 'article model' or 'product model'. You can choose to edit an existing model or create a new one according to your needs.
- Add custom fieldIn the selected model, you will see the "Content Model Custom Field" area. Here, click to add a field, and name your custom parameter.
- Parameter NameThis is the readable name parameter used in the background management interface and front-end template, for example, 'article author', 'source of content'.
- Field invocationThis is the field name stored in the database, as well as the unique identifier referenced in the template.To maintain standardization and easy recognition, it is recommended to use concise English letters, such as “author” representing the author, and “source” representing the source.
- Field type: Choose the data type you want to store, Anqi CMS provides various types such as single-line text, numbers, multi-line text, single selection, multiple selection, dropdown selection, and even image groups.
- Other settingsConfigure whether to require, default values, etc. as needed.
After adding custom fields, remember to save the content model settings.
The second step: fill in custom parameters when publishing or editing articles
After you define the custom parameters in the content model, these custom fields will appear on the article editing page when you publish or edit articles belonging to the model.
- Publish/Edit ArticleGo to 'Content Management' -> 'Document Management', select 'Publish Document' or edit an existing article.
- Select the category it belongs to.Ensure that the "Category" you select is associated with the content model you configured in the first step.
- Enter the parameter valueIn the "Other Parameters" section of the article editing interface, you will see the custom fields defined just now.Here, enter the corresponding values for each parameter. For example, enter the author's name in the 'Article Author' field, and enter the source website in the 'Content Source' field.
After saving the article, these custom parameter values are successfully stored.
Step 3: Display custom parameters in the article detail page template.
Now, the key step is: how can you obtain and display these custom parameters in the article detail page template of your website front-end?The AnQi CMS provides powerful and flexible template tags that can easily achieve this goal.The template file for the article detail page is usually located/template/您的模板目录/archive/detail.htmlOr you can customize the template file for the article in the background.
We will introduce two commonly used methods to obtain and display custom parameters, you can choose the most suitable one according to your actual needs:
Method one: Directly through the field name retrieval (suitable for known and few specific parameters)
If you only need to display a few known custom parameters, such as "author" and "source", and you already know their "field names" defined in the content model (such asauthorandsource), then directly accessing through the field name is the simplest way.
You can usearchiveDetailtags, and specifynameThe name of the 'calling field' for custom parameters.
Code example:
{# 假设自定义参数的调用字段为 author 和 source #}
<div class="article-meta">
{% set articleAuthor = "" %}
{% set articleSource = "" %}
{# 获取作者 #}
{% archiveDetail authorName with name="author" %}
{% set articleAuthor = authorName %}
{% endarchiveDetail %}
{# 获取来源 #}
{% archiveDetail contentSource with name="source" %}
{% set articleSource = contentSource %}
{% endarchiveDetail %}
{% if articleAuthor %}
<span>作者:{{ articleAuthor }}</span>
{% endif %}
{% if articleSource %}
<span>来源:{{ articleSource }}</span>
{% endif %}
</div>
Explanation:
{% archiveDetail authorName with name="author" %}This line of code will try to find the value of the field namedauthorand assign it toauthorName.- By
{% set ... %}to further assign toarticleAuthorandarticleSourceVariables are used to make conditional judgments easier ({% if ... %}) to avoid directly outputting empty content when the parameter does not exist. <span>作者:{{ articleAuthor }}</span>: If the author information is obtained, it will be displayed.
This method is simple and direct, the code is clear, and it is very suitable for scenarios where specific custom parameters are displayed at fixed positions on article detail pages.
Method two: Traverse all custom parameters (suitable for scenarios where the number of parameters is dynamic and requires unified display)
If you have many custom parameters, or you want to display all custom parameters in a list, or you are not sure about the 'calling field' name of each parameter, then usearchiveParamsLabel collaborationforLooping through all parameters will make it more flexible.
archiveParamsThe tag will get all custom parameters of the current article and organize them into an array object for you to loop through.
Code example:
<div class="article-custom-params">
<h4>文章附加信息:</h4>
<ul>
{% archiveParams params %}
{% for item in params %}
<li>
<strong>{{ item.Name }}:</strong> <!-- 显示“参数名” -->
<span>{{ item.Value | safe }}</span> <!-- 显示“参数值”,注意safe过滤器 -->
</li>
{% endfor %}
{% endarchiveParams %}
</ul>
</div>
Explanation:
{% archiveParams params %}This tag retrieves all custom parameters of the current article and stores the result.paramsthe variable.{% for item in params %}We traverse through the loop.paramsarray. In each iteration,itemThe variable represents a custom parameter object.{{ item.Name }}: It will display the parameter name you set in the background (e.g., 'Article Author').{{ item.Value }}: It will display the specific value of the custom parameter you have filled in (e.g., 'Zhang San').| safeThis filter is very important! If your custom parameter values may contain HTML content (such as bold, links, etc. that you have entered in the background "multi-line text" field), use| safeEnsure that this HTML content is correctly parsed by the browser and not displayed as plain text.
The advantage of this method is that the template code does not need to be modified no matter how many custom parameters you add in the background.It will automatically adapt and display all the parameters filled. You can also use theitem.Nameoritem.ValuePerform conditional judgments to implement more complex display logic.
Apply flexibly to enhance content value
By following these steps, you can flexibly retrieve and display the custom parameters of the article detail page in Anqi CMS according to your actual needs.Whether it is simple author information or a complex product specification list, the flexible content model and powerful template tags of Anqi CMS can help you a lot.Make good use of these features, not only can it make your website content more rich and personalized, but it can also greatly enhance the user experience and the effectiveness of content marketing.
Frequently Asked Questions (FAQ)
Q1: I have set up custom parameters and filled in the content in the background, but the article detail page does not display. Why is that?A1: How many kinds?