How can AnqiCMS efficiently display the latest published article list on the homepage?
In website operation, the homepage as the first station for user access, the activity of its content update often determines whether users are willing to stay and delve deeper into browsing.Especially for content-based websites or corporate blogs, the homepage can dynamically display the latest list of published articles, not only presenting fresh content to visitors in the first time, but also a key factor in enhancing user experience and search engine optimization.So, how do we efficiently achieve this goal in AnQiCMS (AnQiCMS)?
Anqi CMS, with its simple and efficient architecture and flexible template system, makes it very intuitive to display the latest article list on the homepage. The core lies in fully utilizing the system providedarchiveListTemplate tags combined with some key parameters can easily achieve content automation updates.
Firstly, to implement the list of "latest published" articles, we mainly rely onarchiveListThis powerful tag is used to filter and retrieve article data from the database.This tag provides rich parameters, allowing us to precisely control the display of the article.Generally, you would place this tag code in your template file, such as in the main template directory.index.htmlfiles, orindex/index.htmlThis depends on the organization of your current template. The Anqi CMS template syntax is similar to Django, very intuitive, you just need to use{% 标签名 参数 %}to call the function, use{{ 变量名 }}to output content.
Make sure the list displays the latest articles,orderThe parameter is indispensable. We can set it toorder="CreatedTime desc"This means that the system will sort the articles based on the publication time (CreatedTime) in descending order, with the latest articles naturally appearing at the top. Of course, if you prefer to judge the newness of articles based on their ID, you can also useorder="id desc". At the same time, throughlimitParameter, you can flexibly control the number of articles displayed on the homepage, for example, set it tolimit="5"The home page will only display the latest five articles. This mechanism is due to the high-performance Go language underlying architecture of AnQi CMS, even if the number of articles on the website is large, it can still ensure fast response and efficient loading.
Here is a simplified code example of displaying the latest article list on the homepage, which clearly shows how to utilizearchiveListTags:
<section class="latest-articles">
<h2>最新发布</h2>
<div class="article-list">
{% archiveList latestArticles with type="list" order="CreatedTime desc" limit="5" %}
{% for item in latestArticles %}
<div class="article-item">
<a href="{{ item.Link }}" title="{{ item.Title }}">
{% if item.Thumb %}
<img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="article-thumb">
{% endif %}
<h3>{{ item.Title }}</h3>
</a>
<p class="article-description">{{ item.Description|truncatechars:100 }}</p>
<div class="article-meta">
<span class="article-date">发布于:{{ stampToDate(item.CreatedTime, "2006年01月02日") }}</span>
<span class="article-views">浏览量:{{ item.Views }}</span>
</div>
</div>
{% empty %}
<p>目前还没有文章发布,敬请期待!</p>
{% endfor %}
{% endarchiveList %}
</div>
</section>
In this example,archiveListtag first defines a variablelatestArticlesto store the retrieved article data.type="list"We specified that we were getting a regular list, not a paged list.order="CreatedTime desc"Ensured that the articles were arranged from new to old by publication time, andlimit="5"It limited to displaying only the latest five articles.
In{% for item in latestArticles %}the loop,itemRepresents the data of each article, we can use throughitem.Linkget the article link,item.TitleGet the title,item.DescriptionRetrieve article summaries,item.Viewsto get the view count. Especiallyitem.ThumbIt allows you to display the thumbnail of the article, making the homepage list more vivid and attractive.If the article does not set a thumbnail, this code will also automatically determine and choose not to display the image.
It is worth noting that,item.CreatedTimeis a timestamp, to convert it to the date format we are familiar with, we usedstampToDatethis auxiliary label, and specified"2006年01月02日"Such Go language time format template makes the date display clearer. At the same time,Description|truncatechars:100The filter can elegantly truncate the article summary to a specified length and add an ellipsis at the end, keeping the page neat.
If the website has not published any articles temporarily,{% empty %}The content inside the block will be displayed, avoiding the embarrassment of a blank page, which is a very considerate design.
In addition to the basic list of latest articles, you can also customize according to your needs. For example, if you want to display only the latest articles under a specific category, you can simply inarchiveListthe tag withcategoryId="你的分类ID"The parameter. The multi-site management feature of AnQi CMS also means that if you are operating multiple websites, you can also go throughsiteIdThe parameter specifies the content to be called from different sites, realizing flexible content display across sites.
In addition, the 'Time Factor-Scheduled Publication Function' of Anqi CMS is also closely related to this.You can edit the article in advance, set the future publication time, and the system will automatically publish it after reaching the specified time and immediately update it to the latest article list on the homepage, greatly improving the flexibility and automation of content operation, allowing you to plan content layout in an orderly manner.
In summary, Anqi CMS, through its intuitive template tags and high-performance backend support, allows website operators to easily and efficiently display the latest published article list on the homepage.This not only enhanced the dynamic feel and user experience of the website, but also laid a solid foundation for content marketing and SEO optimization.
Frequently Asked Questions (FAQ)
Question: How to exclude articles of a specific category when displaying the latest articles on the homepage?Answer: If you want to exclude certain categories that you do not want to display in the latest article list on the homepage, you can use
archiveListlabel'sexcludeCategoryIdthe parameters. For example,{% archiveList latestArticles with type="list" order="CreatedTime desc" limit="5" excludeCategoryId="1,3" %}This will exclude articles under categories with IDs 1 and 3.Ask: I have published a new article, but the homepage did not update immediately. What is the reason?Answer: The AnQi CMS backend has the "Update Cache" feature, which is usually automatically updated after the article is published.If the homepage does not immediately display the latest articles, it may be due to server or browser caching.You can try to click the 'Update Cache' button on the Anqicms CMS backend to clear the system cache, and you can also clear your browser cache (Ctrl+F5 or Cmd+Shift+R) to force refresh the page.
Ask: Besides the publish time, can I sort the latest articles in other ways? For example, by article popularity?Answer: Of course you can.
archiveListlabel'sorderThe parameters are very flexible. In addition toorder="CreatedTime desc"(Sorted by publish time in reverse) ororder="id desc"(Sorted by ID in reverse), you can also useorder="views desc"Sort articles by the number of views (popularity) in descending order to display the most popular articles. If you want to display the manually set order by the editor, you can useorder="sort desc".