In AnQiCMS, flexibly displaying content is one of its core advantages, which not only concerns the user experience but also directly affects the website's SEO performance.The release time, update time, view count, and category of the document are key information that users often focus on, and are also important indicators for search engines to evaluate the timeliness and relevance of content.Fortunately, AnQiCMS provided us with intuitive and powerful template tags, making the display of this information very simple.
Next, we will discuss how to easily display these important document information on your AnQiCMS website.
Display core information on the document detail page.
When browsing a specific article or product details, it is usually necessary to display its publication, update time, view count, and category in a prominent position. This can be done through AnQiCMS'sarchiveDetailLabel it easily.
Display the publication time (CreatedTime) and update time (UpdatedTime):In AnQiCMSCreatedTimeThe field records the publication time of the document, andUpdatedTimeThen records the last update time of the document. These fields store timestamps, and in order to present them in a human-readable format, we need to usestampToDateFormat labels.
For example, if you want to display the publication time in the format of 'Year-Month-Day', you can use it like this:
发布于:{{ stampToDate(archive.CreatedTime, "2006-01-02") }}
If you need to be precise to 'Year-Month-Day Time:Minute', you can do it like this:
更新于:{{ stampToDate(archive.UpdatedTime, "2006-01-02 15:04") }}
HerearchiveRepresents the entire object of the current document, and"2006-01-02"are the date formatting standards in Go language, you can adjust them as needed. It is worth noting that,UpdatedTimeThe display is very important for telling search engines and users that your content is fresh and maintained. If the document content is modified, this time will be automatically updated, andCreatedTimeunchanged.
Show document views (Views):The number of views of a document is an important indicator of its popularity. In AnQiCMS, views are stored inViewsField shows it very directly:
阅读量:{{ archive.Views }}
You can add units like 'times', 'reads', etc. after the numbers according to your design requirements to make the information clearer.
Show the category of the document:Each document belongs to a category, displaying this information helps users understand the context of the content and facilitates their further exploration of related content. You can accessarchive.CategoryThe object directly retrieves the detailed information of the category, such as the category name and link.
所属分类:<a href="{{ archive.Category.Link }}">{{ archive.Category.Title }}</a>
This method is concise and clear, directly utilizing thearchiveDetailtags to obtain the category information contained in the current document object.
In summary, on a document detail page, you might see a layout code similar to the following:
<article>
<h1>{{ archive.Title }}</h1>
<div class="meta-info">
<span>发布于:{{ stampToDate(archive.CreatedTime, "2006-01-02") }}</span>
<span>更新于:{{ stampToDate(archive.UpdatedTime, "2006-01-02 15:04") }}</span>
<span>阅读量:{{ archive.Views }} 次</span>
<span>所属分类:<a href="{{ archive.Category.Link }}">{{ archive.Category.Title }}</a></span>
</div>
<div class="content">
{{ archive.Content|safe }} {# 注意这里使用了safe过滤器以避免HTML内容被转义 #}
</div>
</article>
Display core information on the document list page
On the document list page, such as the homepage, category list page, or search results page, we usually cycle through brief information of multiple documents. At this time, AnQiCMS'sarchiveListthe label comes into play.
archiveListThe tag allows you to get a list of documents based on various conditions such as categories, modules, and recommended attributes. When looping through these documents, you can access each document as you would on a detail page.CreatedTime/UpdatedTime/Viewsand category information.
The following is an example of a document list display, which includes publication time, views, and category.
<div class="document-list">
{% archiveList archives with type="page" limit="10" %} {# type="page"表示启用分页 #}
{% for item in archives %}
<div class="document-item">
<h2><a href="{{ item.Link }}">{{ item.Title }}</a></h2>
<div class="item-meta">
<span>发布于:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
<span>阅读量:{{ item.Views }} 次</span>
<span>所属分类:
{% categoryDetail categoryInfo with name="Title" id=item.CategoryId %}
{% categoryDetail categoryLink with name="Link" id=item.CategoryId %}
<a href="{{ categoryLink }}">{{ categoryInfo }}</a>
</span>
</div>
<p>{{ item.Description }}</p>
<a href="{{ item.Link }}" class="read-more">阅读更多</a>
</div>
{% endfor %}
{% endarchiveList %}
{# 列表页通常会配合分页标签 pagination 使用 #}
{% pagination pages with show="5" %}
{# 这里是分页导航代码 #}
{% endpagination %}
</div>
In this example,itemIsarchiveListEach document object in the loop. We directly go throughitem.CreatedTimeanditem.ViewsGet data. For category information, we useitem.CategoryIdcooperatecategoryDetailtags to get the category ofTitleandLinkbecause in the list loop,item.Categorythe object may not contain the complete category details by default, usingcategoryDetailCan ensure accurate classification information.
Practical Tips and **Practice**
When displaying this information, there are some details that can help you improve the professionalism and user experience of the website:
- Clarify the meaning of tags:Add the words "Published on",
- Make good use of the update time:
UpdatedTimeThe existence is especially important for content that needs to be updated regularly (such as technical tutorials, industry analysis, etc.)It not only indicates the "freshness" of the content to users, but is also an important basis for search engines to judge the quality and timeliness of the content.If your article has not been updated for a long time,UpdatedTimeWill beCreatedTimeThe same, which means that the content has not been modified since it was published. - Flexible date formatting:
stampToDateTags support rich date and time formatting strings in Go language. You can display 'Just now', 'A few minutes ago', or specific year-month-day hour-minute-second based on your design needs, making your website's time display more flexible and diverse. - Categorization navigation guidance:Design the category as a clickable link that can directly jump to the category list page, making it convenient for users to delve into similar content and enhance the internal link structure of the website.
- Scheduled publishing application:AnQiCMS'
CreatedTimeThe field can be set to a future time in the background to achieve scheduled publishing of documents. This means you can schedule documents for publishing before they are officially launched.