How to dynamically add 'Read More' link text to each title on the AnQiCMS article list page?

Calendar 👁️ 59

When managing and operating a website, the article list page is an important entry point for users to browse content and discover information.To enhance the user experience, it is a common practice to dynamically add a 'Read More' or 'View Details' link text to each title in the list to clearly guide visitors to the article details.AnQiCMS provides a powerful and flexible template system, allowing us to easily achieve this function.

When a user sees the article title and a brief summary on the list page, a clear 'Read More' link can quickly guide them to click and get the full content.This not only makes the page layout more tidy, but also provides users with a clear call to action, and also has a positive impact on the internal link structure and SEO of the website.

To implement this feature, we mainly operate on the Anqi CMS template files, which are usually used to display article lists, for example/template/你的模板名/article/list.htmlor/template/你的模板名/article/index.html. Anqi CMS uses a syntax similar to the Django template engine, using{% ... %}to define tags (such as loops, conditional judgments), as well as{{ ... }}to output variable values.

The core idea is to utilize the built-in functions of Anqi CMSarchiveListtags to retrieve article data, and then throughforLoop through each article. Within the loop, we can access various properties of each article, including its detail page link and title.

Firstly, you need to find the template file responsible for rendering the article list page. This is usually located in the corresponding model directory of the template theme you are using, for example, for the article (article) model, it may be located intemplate/您的主题名称/article/list.html.

Open the file and you will see a code block usingarchiveListtags to get the article data, as well as aforloop to iterate through these articles. The detailed links for the articles can be accessed throughitem.LinkGet it, the article title goes throughitem.TitleGet, while the abstract is usuallyitem.Description.

Now, we can add a 'Read More' link to the detail page of the article at any appropriate position in this loop, such as below each article summary or next to the article title.

Here is a specific code example that shows how to add a 'Read More' link below the title and abstract of each article on the article list page:

{# 假设这是您的文章列表页模板文件,例如:/template/您的主题名称/article/list.html #}

<div class="article-list-container">
    {# 使用 archiveList 标签获取文章列表,moduleId="1" 通常代表文章模型 #}
    {% archiveList articles with type="page" moduleId="1" limit="10" %}
        {% for item in articles %}
            <div class="article-item">
                <h3 class="article-title">
                    {# 文章标题本身可以是一个链接 #}
                    <a href="{{item.Link}}">{{item.Title}}</a>
                </h3>
                {# 如果文章有缩略图,可以显示出来 #}
                {% if item.Thumb %}
                    <a href="{{item.Link}}" class="article-thumb">
                        <img src="{{item.Thumb}}" alt="{{item.Title}}">
                    </a>
                {% endif %}
                {# 文章摘要 #}
                <p class="article-description">{{item.Description}}</p>
                
                <div class="article-meta">
                    {# 显示一些文章元信息 #}
                    <span>发布日期: {{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                    <span>阅读量: {{item.Views}}</span>
                    
                    {# 核心部分:动态添加“阅读更多”链接文本 #}
                    <a href="{{item.Link}}" class="read-more-link">阅读更多 &raquo;</a>
                </div>
            </div>
        {% empty %}
            {# 如果当前分类下没有文章,显示此提示 #}
            <p class="no-content">当前分类下暂无文章。</p>
        {% endfor %}
    {% endarchiveList %}

    {# 分页代码通常紧随文章列表之后,这里仅为示例结构,具体样式请根据您的模板调整 #}
    <div class="pagination-container">
        {% pagination pages with show="5" %}
            <a class="{% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">首页</a>
            {% if pages.PrevPage %}
                <a href="{{pages.PrevPage.Link}}">上一页</a>
            {% endif %}
            {% for p in pages.Pages %}
                <a class="{% if p.IsCurrent %}active{% endif %}" href="{{p.Link}}">{{p.Name}}</a>
            {% endfor %}
            {% if pages.NextPage %}
                <a href="{{pages.NextPage.Link}}">下一页</a>
            {% endif %}
            <a class="{% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{pages.LastPage.Link}}">尾页</a>
        {% endpagination %}
    </div>
</div>

In the code above,{{item.Link}}The link will dynamically be replaced with the actual link address of each article, and阅读更多 &raquo;which is the custom link text we use.class="read-more-link"The setting is designed to make it convenient for you to beautify this link through CSS styles, making it look more like a button or highlight it.

Advanced optimization and customization:

  • Variety of link text:You can replace 'Read more' with 'View details', 'Learn more', or any other text that fits the tone of your website. For example:<a href="{{item.Link}}" class="read-more-link">查看详情</a>.
  • Add style:By modifying the CSS file of your template, you can add background color, border, padding, and other styles to the class.read-more-linkto make it appear as a button, thereby enhancing its visual appeal.
  • Conditional display:If you want to display the 'Read More' link only when the article has an abstract or the content length exceeds a certain limit, you can useifcondition judgment. For example:{% if item.Description %}<a href="{{item.Link}}">阅读更多</a>{% endif %}.
  • Open in a new window:If you want the article to open in a new window after clicking the link, you can<a>the tag withtarget="_blank"attribute:<a href="{{item.Link}}" target="_blank">阅读更多 &raquo;</a>.
  • SEO attributes:As needed, you can addrel="nofollow"attributes, to tell the search engine not to track the link, for example:<a href="{{item.Link}}" rel="nofollow">阅读更多 &raquo;</a>.

By following these steps, you not only added a practical 'Read More' link to the article list page of AnQi CMS, but also optimized user browsing through flexible template customization

Related articles

How do you handle the case when one of the variables is `nothing` or `nil` while using the `add` filter, and what will be the output result?

In AnQiCMS template development, we often need to perform simple addition operations or string concatenation, the `add` filter is created for this purpose.It is very convenient to use, and can intelligently handle addition of numbers and concatenation of strings.If you give it two numbers, it will perform mathematical addition;If you give it two strings, it will concatenate them.Even if it is a mixture of numbers and strings, AnQiCMS will try to make a reasonable conversion and output the result.For example, add numbers: twig {{ 5|add:2 }} {#

2025-11-07

In AnQiCMS template, why does `{{ 5|add:"CMS" }}` output `5CMS`? What are the rules for mixing numbers and strings in concatenation?

In AnQiCMS template development, we sometimes encounter some seemingly simple expressions that hide clever logic.Among the phenomenon that `{{ 5|add:"CMS" }}` finally outputs `5CMS`, it often makes friends who are new to it feel curious.This involves the unique rule of mixed number and string splicing in AnQiCMS template engine.Today, let's delve deeper into this interesting mechanism.### The "filter" in AnQiCMS template and the magic of `add` In AnQiCMS

2025-11-07

How does the `add` filter seamlessly concatenate the values of two string variables?

In AnQiCMS template development, we often need to combine different data fragments, whether it is the calculation of numbers or the integration of text information.Among them, the `add` filter is a very practical and flexible tool that can help us easily perform the "addition" operation of two variable values, achieving seamless splicing effects.The design philosophy of the `add` filter is to take into account both numeric calculations and string concatenation.When you apply it to two numeric variables, it performs standard mathematical addition to calculate their sum.

2025-11-07

How can the `add` filter be used to perform exact addition of numbers in the Anqi CMS template?

In Anqi CMS template development, we often need to perform calculations on numbers, such as counting the total price of a product or dynamically adjusting the display quantity.The AnQi CMS template engine provides a rich set of filters to handle these scenarios, where the `add` filter is a powerful tool for adding numbers or concatenating strings.It handles the data calculation needs in templates with its intelligent type handling mechanism.

2025-11-07

What is the practical difference in applying the `add` filter and the `stringformat` filter in template string concatenation?

In the AnQi CMS template world, flexibly handling strings is an indispensable skill for building dynamic web pages.Among them, the `add` filter and the `stringformat` filter can help us concatenate or combine strings, but their design philosophy and application scenarios are obviously different.Understanding these differences allows us to make more informed choices when developing templates, resulting in more efficient and readable code.### `add` filter: A concise and intuitive concatenation tool `add`

2025-11-07

How to use the `add` filter to dynamically add 'Yuan' or a specific currency symbol after the product price?

When managing website content, especially when it involves product display, we often need to present price and other numerical information in a more user-friendly manner.单纯显示一串数字,比如 `199`,往往不够直观,如果能自动加上货币符号,比如 `199元` 或 `$199`,就能大大提升信息的可读性和专业性。AnQiCMS (AnQiCMS) with its flexible template system makes it very simple to meet such requirements, and the key to this is the clever use of the `add` filter.### Understand `add`

2025-11-07

How to use the `add` filter to build dynamic SEO-friendly URL paths in the Anqi CMS template?

In Anqi CMS template creation, flexible and SEO-friendly URL paths are the key to improving the website's search engine performance.Although AnQi CMS provides powerful pseudo-static rule configuration capabilities in the background, generating static URLs through patterns such as `/module-id.html`, but in certain specific scenarios, we may need to control or combine the local URL path more dynamically and finely within the template to meet unique business needs or marketing strategies.At this point, the `add` filter has become a very practical auxiliary tool.###

2025-11-07

How to use the `add` filter in a `for` loop to dynamically generate a unique `id` or `class` attribute for list items?

In AnQi CMS template development, we often need to handle the display of dynamic lists.Whether it is an article list, product display, or other content block, dynamically generating a unique `id` or `class` attribute for each item in the list is particularly important in order to achieve finer style control, JavaScript interaction, or to ensure the uniqueness of page elements.Today, let's talk about how to cleverly use the `add` filter in the `for` loop of AnQiCMS to achieve this goal.### Understanding the demand for dynamic attribute generation Imagine that

2025-11-07