How to make users quickly understand the content of the article on the search results page without showing the full text, which is not only related to user experience but also a key aspect of search engine optimization (SEO).For friends using AnQiCMS, achieving this is very flexible and efficient.
It is usually the case that when we want to display a list of articles on the search results page, if we present the full content of the articles directly, it not only leads to a long page, making it difficult for users to quickly browse, but may also cause a lot of duplicate content, negatively impacting the SEO performance of the website.Search engines tend to display concise summaries on list pages, encouraging users to click into detail pages for full information.
The Anqi CMS took full consideration of flexibility in content display and SEO friendliness from the very beginning.It allows us to precisely control the content fragments displayed on different pages.To make the search results page display the article summary instead of the full text, it mainly involves modifying a specific template file.
Understanding the importance of article summaries
In AnQi CMS, each article has a 'Document Summary' field.This field is specifically used to store a brief overview of the article. Its role is like an advertisement on the cover of a book, needing to be attractive enough and accurately convey the core content of the article.
When you publish or edit articles in the background "Content Management", you will see the "Document Introduction" fill-in area.The Anqi CMS is very intelligent: If you manually fill in the introduction, the system will prioritize it;If you do not fill in, the system will automatically extract the content as a summary from the first 150 words of the article.We strongly recommend that you write a unique introduction for each article, as this can:
- Improving Click-Through Rate (CTR)A compelling introduction can better catch the user's attention, making them interested in clicking to view the details page.
- Avoid duplicate contentOn the list page, displaying the introduction can effectively avoid repetition of content with the article detail page, thus optimizing SEO and avoiding penalties from search engines.
- Optimize search rankings: Search engines also refer to the introduction content when evaluating page relevance. A high-quality introduction helps improve the visibility of the article in search results.
Locate the search results page template
The template files of AnQi CMS are uniformly stored in the system's/templatedirectory. Different page types correspond to different template files. For search result pages, the corresponding template file is usuallysearch/index.html.
If you deploy AnQi CMS through tools like Baota panel or 1Panel, you can directly find and edit these files in the "Template Design" feature in the background. Alternatively, you can also manually modify them by connecting to the server via FTP/SFTP tools./template/您的模板目录/search/index.htmlFile. Please backup the original file before making any modifications in case anything goes wrong.
Modify the template to display the article summary.
Entersearch/index.htmlAfter the template file, you will find that it contains code for displaying the article list in a loop. Anqi CMS uses syntax similar to Django template engine, and the article list is usually displayed through{% archiveList %}tags to obtain.
Inside a loop{% for item in archives %}You may find something similar to{{item.Content|safe}}This line of code is used to display the full content of the article. Now, we need to replace it with code that displays the article summary.
Example of code that might originally display the full text:
{% archiveList archives with type="page" q=urlParams.q limit="10" %}
{% for item in archives %}
<li>
<a href="{{item.Link}}">
<h5>{{item.Title}}</h5>
{# 这里可能是显示全文的代码 #}
<div>{{item.Content|safe}}</div>
{# ... 其他文章信息 ... #}
</a>
</li>
{% empty %}
<li>
抱歉,没有找到相关内容。
</li>
{% endfor %}
{% endarchiveList %}
Example of code that displays the article summary after modification:
{% archiveList archives with type="page" q=urlParams.q limit="10" %}
{% for item in archives %}
<li>
<a href="{{item.Link}}">
<h5>{{item.Title}}</h5>
{# 修改为显示文章简介,并用 truncatechars 限制长度,同时保证 HTML 安全 #}
<div>{{item.Description|truncatechars:150|safe}}</div>
<div>
<span>{% categoryDetail with name="Title" id=item.CategoryId %}</span>
<span>{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
<span>{{item.Views}} 阅读</span>
</div>
</a>
{% if item.Thumb %}
<a href="{{item.Link}}">
<img alt="{{item.Title}}" src="{{item.Thumb}}">
</a>
{% endif %}
</li>
{% empty %}
<li>
抱歉,没有找到相关内容。
</li>
{% endfor %}
{% endarchiveList %}
There are a few key points:
{{item.Description}}: This is the tag to get the content of the article summary field.|truncatechars:150: This is a very practical filter, which can truncate the content of the profile to a specified character length (here 150 characters), and automatically add “…” at the end to indicate truncation.The benefit of doing this is that no matter how long your summary is, it will always display at a consistent length on the search results page, making the page look neater.You can adjust the number 150 according to your actual needs.|safeThis filter is also very important. Because your profile content may contain bold, links, and other HTML tags.|safeTells the template engine that this content is safe, does not need to escape HTML tags, thus ensuring that it can be displayed normally rather than displayed as plain text HTML code.
After completing the modification, save the template file, and clear the website cache (from the backend homepage or the "Update Cache" feature), refresh the search results page, and you will see that the article list no longer displays the full text but instead shows a concise summary.
Content operation tips
Since we have adjusted the content display of the search results page to be concise, it is particularly important to make good use of this summary field.
- Carefully written, avoid emptiness: Even though the summary is automatically extracted from the text, writing it manually can make the summary more marketing-oriented and attractive.
- Integrate keywordsIncorporate core keywords巧妙地在简介中融入核心关键词巧妙地 into the introduction without affecting the reading experience, which helps search engines better understand the theme of the article。
- Regularly review and optimize定期审视与优化Based on website traffic statistics and user feedback, regularly check the effectiveness of the article introduction and make necessary adjustments and optimizations.
By modifying these simple templates and content operation strategies, your Anqi CMS website will provide users with a better browsing experience on the search results page, while also effectively improving the website's SEO performance.
Frequently Asked Questions (FAQ)
Q1: How do I handle it if my article summary is too long or too short?A1: You can use the template to|truncatechars:数字filter to control the display length of the summary, for example{{item.Description|truncatechars:150|safe}}The introduction will be truncated to 150 characters. For the content of the introduction itself, even though the system will automatically extract it, we still recommend that you manually write it in the background to make it concise and attractive, with a length controlled between 50-150 words to achieve a better display effect.
Q2: Do you also want to display summaries in the article list on the category page or tag page? Is the operation the same?A2: Yes, the operation is very similar. The category page (usually){模型table}/list.htmlOr custom category templates) and tabs (usuallytag/list.htmlortag/index.htmlThe article list also usually uses{% archiveList %}Labels to display articles in a loop. Therefore, you only need to find the corresponding position of the article content in these template files (usually{{item.Content|safe}}), and replace it with{{item.Description|truncatechars:150|safe}}Just do it.
Q3: If I do not fill in the introduction manually, will the system generate it automatically?A3: Yes, Anqi CMS is very intelligent. If you do not manually fill in the 'Document Summary' when publishing or editing an article, the system will automatically extract content from the first 150 characters of the article body as the summary of the article.Although this ensures that each list item has a description, manually written descriptions are often more targeted and attractive, which is more beneficial for SEO and user click-through rates.