How to quickly count the number of words (or Chinese words) in the content of an article in AnQi CMS using the `wordcount` filter, for SEO or reading time evaluation?

Calendar 👁️ 75

In website operation, the quality and presentation of content are crucial.The number of words in an article not only affects its performance in search engines, but is also a key indicator for evaluating user reading experience and estimating reading time.No doubt, manually counting the number of words in content is a tedious task, especially when the volume of content is large. 幸运的是,AnQiCMS (AnQiCMS) 为我们提供了一个小巧而强大的工具——wordcountFilter, making content word count easy.

Why is content word count so important?

For content operators, mastering the word count of articles has many aspects meaning:

  1. SEO optimization:When evaluating content quality, the length of an article is often an important indicator of its depth and comprehensiveness in search engine algorithms.An article of moderate length (for example, an in-depth blog post is usually recommended to be between 800-2000 words) is more likely to achieve better search engine rankings.By quickly counting the number of words, we can ensure that the article reaches or exceeds the minimum word count recommended by the industry, thereby improving SEO performance.
  2. User experience and reading duration assessment:Users often quickly scan the title and general structure of an article before clicking on it. Being able to see the "estimated reading time" will greatly enhance the user experience.wordcountThe filter can help us accurately obtain the word count of an article, thereby estimating the approximate reading time, giving readers a clear expectation of the time spent on the content.
  3. Content strategy planning:When creating a content publishing plan, different types of content may require different lengths.For example, a quick news report may only require hundreds of words, while a deep industry report may require thousands of words.The word count tool helps us maintain the consistency and standardization of content creation, ensuring that each piece of content meets the established strategy requirements.

wordcountThe filter makes statistics simple

Of Security CMSwordcountThe filter is a convenient feature built into the template engine, specifically used for counting the number of 'words' in a string.This 'word' is not a strict linguistic definition, but is calculated based on space separation or continuous text blocks.This means that whether it is an English word or a continuous Chinese character, it can naturally perform a count and return an integer result representing the 'length' of the content.

UsewordcountThe filter is very intuitive, mainly there are two ways, we can choose flexibly according to our actual needs.

Method one: act directly on the variable

This is the most common usage, especially for counting the number of characters in the article content field.

Suppose we want to count the characters in the current article detail page.archive.ContentThe number of characters in the (article content) field, just add the following code in the template (such asarchive_detail.htmlordetail.html) as follows:

<p>文章字数:{{ archive.Content|wordcount }} 字</p>

This code will output directlyarchive.ContentThe number of words. For example, if the article content is "安企CMS is a corporate-level content management system based on Go language development", it may count "10" words ("安企CMS", "is", "a", "corporate-level", "content management system", "based on", "Go", "language", "development", "the", "corporate-level content management system").For Chinese, continuous characters are treated as a whole for counting, which is very convenient in practical applications.

Method two: combine{% filter %}Tag usage

When we need to count a text that is generated, combined, or defined through other template tags,{% filter %}the tag comes into play.

For example, we may have a text that is through,loremLabel generated placeholder text, or a string composed of multiple variables:

{% set dynamic_text = "这篇文章的内容很长,安企CMS提供了wordcount过滤器来统计字数。它真的很好用!" %}

<p>动态文本字数:{% filter wordcount %}{{ dynamic_text }}{% endfilter %} 字</p>

{# 也可以用于通过其他标签生成的内容,例如: #}
<p>随机生成文本字数:{% filter wordcount %}{% lorem 25 w %}{% endfilter %} 字</p>

Here, {% filter wordcount %}and{% endfilter %}Enclose the text that needs to be counted, and then the system will calculate the number of words in this part of the content.This approach provides greater flexibility, allowing us to accurately count any form of text block within the template.

Application and tips

MasteredwordcountAfter the filter, you can integrate it into multiple aspects of the website:

  • Article detail page display:Clearly display "About X words" under or in the sidebar of each article title, making it clear to readers.
  • Estimated reading time:Based on the number of words counted, we can further estimate the reading time. For example, if the average reading speed is 250 words per minute, then the reading time can be calculated as follows:
    
    {% set word_count = archive.Content|wordcount %}
    {% set reading_time_minutes = (word_count / 250)|floatformat:"0" %} {# 使用floatformat保留整数,或者根据需要保留小数 #}
    <p>本文约 {{ word_count }} 字,预计阅读时长 {{ reading_time_minutes }} 分钟。</p>
    
  • Content review prompt:In the background custom feature, although it cannot be directly validated by template tags at the time of submission, a custom column can be added to the content management interface to display the word count of the article, making it convenient for operation personnel to quickly review whether the content meets the standard.

Summary

Of Security CMSwordcountThe filter is a simple yet extremely efficient tool that helps website operators easily meet the needs of content word count statistics.In order to improve SEO rankings, optimize the user reading experience, or better plan content strategies, this filter can help you a lot.The flexible application can make your content management work more proficient, adding a touch of elegance to your website.


Frequently Asked Questions (FAQ)

Q1:wordcountHow does the filter define 'word' when counting Chinese content?A1:wordcountThe filter counts continuous Chinese text blocks as a single 'word' when counting Chinese content, rather than counting each character separately.For example, “Anqi Content Management System” is considered as a single word (if it appears as a whole and is not surrounded by spaces), while “Anqi CMS” is considered as two words.This mechanism is very natural in use and usually meets the needs of evaluating the length of an article.

Q2: Besides the article body (archive.Content)wordcountWhat else can the filter be used to count?A2:wordcountThe filter can be applied to any text variable, whether it is an article title, summary, custom field, or through other template tags such asloremGenerated text. Any string data can be processed through{{ 变量|wordcount }}or{% filter wordcount %}{% endfilter %}to count the number of words.

Q3: How to usewordcountthe counted number of words for more accurate reading time estimation?A3:wordcountThe number of words provided is an integer. To estimate reading time, you need to set an average reading speed (for example, 200-300 words per minute).Then divide the total number of characters by this average speed to get the minutes.If you need to be accurate to seconds, you can then multiply the decimal part by 60.In practice, it is usually taken as an integer minute, or rounded to the nearest minute to keep it concise. For example,{{ (word_count / 250)|floatformat:"0" }}The result will be rounded to the nearest whole minute.

Related articles

How to center, left-align, and right-align Chinese string with specified width using `center`, `ljust`, and `rjust` filters in the Anqi CMS template?

When building and maintaining website content, we often need to pay attention to the visual presentation of information, especially the alignment of text content.It is particularly important to accurately control the centering, left alignment, or right alignment of strings, whether it is for the neatness and beauty of the table or to maintain visual balance within a fixed width area.AnQiCMS with its flexible and powerful template engine, provides us with several very practical filters to easily achieve this goal, even for strings containing Chinese characters.

2025-11-08

How to split a normal string into an array of individual characters using the `make_list` filter in the Anqi CMS template for more refined text processing?

In the world of AnQi CMS templates, we often need to process content in various ways, sometimes by paragraphs, sometimes by sentences, and sometimes, we need to refine the text more finely, down to every character.When conventional string processing methods fail to meet such refined needs, the `make_list` filter can excel, as it can split a common string into an array of individual characters, providing unprecedented flexibility for template designers.

2025-11-08

How to use the `split` filter to convert the custom delimiter string returned by the Anqie CMS backend (such as "keyword1|keyword2") into an array for easy traversal?

In AnQi CMS content management practice, flexibility is the key to improving efficiency and achieving personalized display.Sometimes, we may encounter such a requirement: the backend returns a string of text separated by a special symbol through a custom field, such as a product introduction may have multiple related keywords, and it is stored as 'keyword1|keyword2|keyword3' such a format.How can I beautifully split this string of text into individual keywords and make them convenient for display or iteration in a front-end template?

2025-11-08

How to use the `join` filter to concatenate the multiple tags (array) of an Anqi CMS article into a comma-separated string output?

AnQiCMS (AnQiCMS) is loved by website operators for its flexible and efficient features.In daily content management, articles or products often associate with multiple tags (Tag), which are stored in the system in the form of an array.When we need to display these tags on the front-end page, for example, showing

2025-11-08

How to use the `wordwrap` filter in AnQi CMS template to automatically wrap long text and avoid layout chaos or overflow?

In website content operation, we often encounter situations where the text content is too long, causing page layout chaos, even overflowing the container, which seriously affects the user experience.Especially when a continuous English word without spaces or a long string of Chinese characters appears in a narrow area, the default line break mechanism of the browser may not meet our design requirements.Fortunately, AnQi CMS provides a very practical tool for template developers to elegantly solve this problem - that is the `wordwrap` filter.

2025-11-08

How to automatically identify URLs and email addresses in the text and convert them into clickable links in `urlize` and `urlizetrunc` filters in AnQi CMS?

In Anqi CMS, we often encounter scenarios where we need to display website or email addresses in the article content, comments, or other user input text.If these addresses are only plain text, users will not be able to click and jump directly, which will greatly reduce the user experience of the website.Fortunately, Anqi CMS is built-in with powerful template filters, among which `urlize` and `urlizetrunc` are specifically designed to solve this problem. They can automatically convert identified URLs and email addresses into clickable HTML links.

2025-11-08

How to safely output HTML code passed from the backend in Anqi CMS template using the `safe` filter without escaping?

Build and manage websites in AnQi CMS, we often make good use of its powerful and flexible template system to present colorful content.The template engine of AnQi CMS has adopted the syntax of Django templates, which brings us a familiar development experience and powerful features.However, when handling HTML code passed from the backend to the frontend, we encounter an important security mechanism: **automatic escaping**.

2025-11-08

The `dump` filter has what practices in debugging Anqi CMS templates, and how to clearly view the structure and value of complex variables?

During the template development process of AnQi CMS, we often encounter the need to view variable content and structure, especially when dealing with complex objects passed from the background.If you cannot clearly know what is inside the variable, debugging will be as difficult as a blind man feeling an elephant.The AnqiCMS adopts the Pongo2 template engine syntax similar to Django, providing rich tags and filters to help us build dynamic pages, one extremely powerful debugging tool is the `dump` filter.### `dump` filter

2025-11-08