In the daily operation of AnQi CMS, keywords are undoubtedly the core of content strategy.Whether it is to help users find your website through search engines or to enhance the relevance and user experience of on-site content, "keywords" play a crucial role.The "auto" keyword library management function provided by Anqi CMS helps us centrally manage and optimize these valuable words.But how to make the keywords input by the background to be more flexible, intelligent, and automated in the front-end template?splitFilter.
The importance of keywords in the security CMS
AutoCMS is a content management system designed specifically for small and medium-sized enterprises and content operation teams, which provides many conveniences in terms of SEO optimization.Among them, the 'Keyword Library Management' feature is a major highlight.It is not just a simple list of words, but also a center for strategies.
- Centralized managementEnglish: Store all core keywords, long-tail keywords, and business-related terms uniformly to facilitate search and reuse.
- English: Optimize contentIn publishing articles, products, or single-page content, you can quickly select appropriate words from the keyword library to associate with, ensuring that the content revolves around the core theme to enhance SEO.
- Auxiliary Strategy:Combining the advanced features of 'Keyword Auto Expansion' and 'Article Auto Collection' in Safe CMS (as mentioned in the historical update logs), the keyword library can further unleash its automation advantages, providing endless inspiration and materials for content creation.
We usually add keywords to articles in English commas,Separate multiple keywords in one go, for example,splitFilter.
splitFilter: Bridge between backend and frontend
We input the keyword, which is often stored in the database as a complete string.For example, a keyword field of an article may store 'SEO optimization, website operation, content marketing'.To convert them into independent, operable elements on the front end, you first need a 'cutting' action.splitThe filter is created for this purpose.
Its basic function is to split a string into an array of strings according to the delimiter we specify. For example,"SEO优化, 网站运营, 内容营销"|split:", "This operation will split this long string into an array containing three elements: ["SEO优化", "网站运营", "内容营销"]Once you have this array, we can individually traverse and process each keyword in the template.
How to implement automatic extraction and processing of keywords
Let's take a step-by-step look at how to make use ofsplitThe filter, in conjunction with the keyword library management function, to achieve intelligent extraction and processing of keywords.
Step 1: Build and maintain your keyword library
Firstly, ensure that your keyword library is rich and accurate. You can enrich it in the following ways:
- Manual additionEnglish: In the “Function Management” -> “Keyword Library Management” of the AnQi CMS backend, add your core keywords one by one.
- Batch import:If you already have a large list of keywords, you can quickly import them into the keyword library through the batch import feature of the background.
- English:Using the built-in 'Keyword Auto-Expansion' feature of AnQi CMS, the system will intelligently expand more relevant keywords for you based on existing keywords, further enriching your keyword resources.
第二步:将关键词赋能内容
When editing articles, products, or single pages, you need to associate keywords from the keyword library with specific content.In the "Add Document" or "Edit Document
- 从关键词库选择:点击选择按钮,从你的关键词库中挑选合适的词汇。
- 手动输入If the library does not contain the keyword you want, you can also enter it manually,Make sure to use English commas
,to separate different keywords, this issplitthe basis for the filter to correctly identify.
When the content is published, these keywords will be stored in the article as a comma-separated string.KeywordsThe field is waiting for the call of the front-end template.
Step 3: Use it flexibly in the front-end template.splitFilter
Now, we come to the front-end template, such as the article detail page (archive_detail.html) Suppose we want to display a row of clickable keywords tags below the article title:
{# 获取当前文章的关键词字符串 #}
{% archiveDetail keywordsString with name="Keywords" %}
{% if keywordsString %}
{# 使用split过滤器将关键词字符串切割成数组,注意分隔符是", "(逗号加一个空格)#}
{% set keywordArray = keywordsString|split:", " %}
<div class="article-keywords">
<i class="fas fa-tags"></i>
{% for keyword in keywordArray %}
<a href="/tag/{{ keyword|urlencode }}" class="keyword-tag">{{ keyword }}</a>
{% endfor %}
</div>
{% endif %}
In the above code:
{% archiveDetail keywordsString with name="Keywords" %}This line of code retrieves the value from the article details.KeywordsAssigns the value of the field to.keywordsStringa variable.{% set keywordArray = keywordsString|split:", " %}This is the core step.splitThe filter makes its appearance. It willkeywordsStringFor example, “SEO optimization, website operation, content marketing”", "Split by commas and spaces, generate a namedkeywordArrayusing a comma as a delimiter.{% for keyword in keywordArray %}We useforto iteratekeywordArraywith each keyword.<a href="/tag/{{ keyword|urlencode }}" class="keyword-tag">{{ keyword }}</a>In the loop, we dynamically generate a link for each keyword, pointing to the tag page of the Security CMS (assuming the tag URL structure is)/tag/你的关键词), and appliedurlencodeThe filter ensures that the keywords in the URL are safe.
This is an automatic translation. It parses the keywords either manually entered or selected from the keyword library and displays them beautifully and practically in the form of tags on the front end.
Advanced Application:splitCombination of Filters with Other Filters
splitCombination of Filters with Other Template Filters, which can realize more complex automation processing:
- Keyword De-duplicationAlthough
splitThe system does not provide deduplication functionality, but you can implement deduplication after cutting into an array (usually in the back-end controller or through JS on the front-end, deduplication directly in the template layer is relatively complex).But on display, if there are duplicate keywords, it can be allowed, as this often represents the importance of the word. - Keyword Counting:If you want to know how many times a specific keyword appears in the article keyword list, you can first
splitarrayed, and then combinecounta filter (althoughcountThe filter is usually used to calculate the number of occurrences of specific elements in strings or arrays, but for exact matching within arrays, it can be done directly). - Keyword replacement or modification: When the keyword is
splitAfter forming an array, if necessary