How can AnQi CMS efficiently display the latest published article list on the homepage?
In website operation, the homepage serves as the first stop for users visiting. The activity of content updates 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. It not only presents fresh content to visitors first, but also plays a key role in enhancing user experience and search engine optimization.How do we efficiently achieve this goal in AnQiCMS (AnQiCMS)?
AnQi CMS, with its concise 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 Releases' articles, we mainly rely onarchiveListThis powerful tag is used to filter and retrieve article data from the database.This tag provides a rich set of parameters, allowing us to accurately control the display style of the article.index.htmlfiles, orindex/index.htmlThis depends on how you organize your current template. The Anqi CMS template syntax is similar to Django, very intuitive, you just need to use{% 标签名 参数 %}to call the function, and{{ 变量名 }}to output the 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 in descending order based on the publication time (CreatedTime), with the latest articles appearing at the top. Of course, if you prefer to judge the newness of the articles based on their IDs, you can also useorder="id desc"Also, bylimityou can flexibly control the number of articles displayed on the homepage, for example, set it tolimit="5"The homepage will only display the latest five articles.This mechanism benefits from the high-performance Go language underlying architecture of Anqi CMS, ensuring fast response and efficient loading even with a large number of articles on the website.
Here is a simplified code example displayed on the homepage showing 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,archiveListThe tag first defines a variablelatestArticlesto store the fetched article data.type="list"We have specified that we are getting a regular list, not a paginated list.order="CreatedTime desc"Ensure that the articles are arranged from new to old by publication time,limit="5"It limited the display to only the latest five articles.
In{% for item in latestArticles %}in the loop,itemrepresents the data of each article, we canitem.LinkGet article link,item.Titleto get the title,item.Descriptionto get the article summary,item.Viewsto get the view count. Especiallyitem.ThumbIt allows you to display the thumbnail of the article, making the home page list more vivid and attractive.If the article does not have a thumbnail set, this code will also automatically judge 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 tag 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 to keep the page tidy.
If the website has not published any articles temporarily,{% empty %}The content within the block will be displayed, avoiding the embarrassment of a blank page. This is a very thoughtful 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 inarchiveListtag.categoryId="你的分类ID"Parameters. The multi-site management feature of AnQi CMS also means that if you are operating multiple websites,siteIdThe parameter specifies the content of different sites, realizing flexible content display across sites.
In addition, the 'Time Factor - Scheduled Release Feature' of AnQi CMS is also closely related.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 enhancing the flexibility and automation of content operation, allowing you to plan content layout in an orderly manner.
In summary, Anqi CMS allows website operators to easily and efficiently display the latest list of published articles on the homepage through its intuitive template tags and high-performance backend support.This not only enhances the dynamic feel and user experience of the website, but also lays a solid foundation for content marketing and SEO optimization.
Common 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
archiveListTagsexcludeCategoryIdparameters. 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 published a new article, but the homepage did not update immediately. What could be the reason?Answer: The backend of AnQi CMS has a 'Update Cache' feature, which usually updates the cache automatically after an article is published.If the homepage does not immediately display the latest articles, it may be due to caching on the server side or the browser side.You can try to click the 'Update Cache' button on the AnQi CMS backend to clear the system cache. You can also clear your browser cache (Ctrl+F5 or Cmd+Shift+R) to force refresh the page.
Ask: Besides the publication time, can I sort the latest articles in other ways? For example, by article popularity?Answer: Of course you can.
archiveListTagsorderThe parameter is very flexible. In addition,order="CreatedTime desc"(Sorted by release 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".