In website operation, friendship links are an important factor in improving website weight, increasing external traffic, and optimizing user experience.AnQiCMS (AnQiCMS) knows this, therefore it provides a convenient link management function in the system design, and supports flexible calls and display in templates.This article will introduce you in detail how to obtain and display the friend link list in your AnQiCMS template.

Management of friend links: Starting from the background

Before calling the template, first make sure that the link management function of your website background is configured. The AnQi CMS link management function is located atfunction managementUnder the module. Here, you can add new友情链接 links, edit information of existing links, including the link name (Title), target address (Link), brief remarks (Remark), and whether to enable the "nofollow" attribute (Nofollow).

The “nofollow” attribute is very important for SEO, as it tells search engines not to follow the link. This is very useful when linking to external websites and not wanting to pass on your own weight.AnQiCMS provides the convenience of checking this option for you in the background.

These friendship links configured in the background are the data source we will obtain and display in the front-end template.

The core tag for obtaining friendship links in the template:linkList

AnQiCMS provides a namedlinkListThe dedicated template tag is used to retrieve and display the friend links configured on the back-end of your website.This label is designed to be very intuitive, allowing you to easily integrate link data into any template location.

Basic syntax is as follows:

{% linkList 变量名称 %}
    {# 在这里放置循环代码来遍历和显示友情链接 #}
{% endlinkList %}

Here, 变量名称Is a custom name you use to store the list of friend links, for examplefriendLinks.linkListThe tag will retrieve all enabled friend links and assign them to the specified variable as a list object.

Detailed explanationlinkListThe use of tags

due tolinkListThe tag will return the friend link as a list (or array), therefore, you need to use the AnQiCMS template engine providedforLoop the tag to iterate and display each friend link.

Each friend link item contains the following available information:

  • item.Title: Display name of the friend link.
  • item.Link: The target URL address of the friendship link.
  • item.Remark: Remarks information of the friendship link, usually used for brief descriptions or prompts.
  • item.NofollowA boolean value (or 0/1 as a number), indicating whether the link has been setrel="nofollow"property. Whenitem.Nofollowis set to 1, it indicates that it has been set.

Here is a complete code example demonstrating how to retrieve and display friend links in your template:

{# 使用linkList标签获取友情链接列表,并将其存储在名为friendLinks的变量中 #}
{% linkList friendLinks %}
    {# 首先判断friendLinks变量是否存在且不为空,以避免在没有链接时显示空区域 #}
    {% if friendLinks %}
        <div class="footer-links">
            <h3>友情链接</h3>
            <ul class="friendship-links-list">
                {# 遍历friendLinks中的每一个友情链接项目,每个项目命名为item #}
                {% for item in friendLinks %}
                    <li>
                        {# 创建a标签,设置链接地址为item.Link,显示文本为item.Title #}
                        {# 使用target="_blank"确保链接在新窗口打开,提高用户体验 #}
                        {# 根据item.Nofollow的值判断是否添加rel="nofollow"属性,保障SEO策略 #}
                        <a href="{{item.Link}}" {% if item.Nofollow == 1 %} rel="nofollow"{% endif %} target="_blank">{{item.Title}}</a>
                        {# 如果存在备注信息,可以将其显示在链接旁边,通常用span标签包裹并添加样式 #}
                        {% if item.Remark %}
                            <span class="link-remark">{{item.Remark}}</span>
                        {% endif %}
                    </li>
                {% endfor %}
            </ul>
        </div>
    {% endif %}
{% endlinkList %}

Place this code in the template file where you want to display the friend links (for example, the footer filepartial/footer.htmlor the sidebar filepartial/sidebar.htmlIn it, save and you will see the effect on the front page. You can beautify the display effect of the friendship link by modifying the HTML structure and adding CSS styles, so that it matches the style of your website.

in a multi-site scenariositeIdParameter

If you are using the multi-site management feature of AnQiCMS and want to callother sitesthe friend link list of a site template,siteIdTo implement the parameter. For example, if you want to call the friendship link of the site with ID 2:

{% linkList friendLinks with siteId="2" %}
    {# 循环显示 ID 为 2 的站点的友情链接 #}
{% endlinkList %}

In most single-site cases, this parameter does not need to be manually set, the system will default to obtaining the current site's link.

Consider integrating the link into the template in practice.

  1. Location selection:The most common places for friend links are the website's footer, sidebar, or an independent 'friend links' page.Choose a location that is friendly to both users and search engines.
  2. Customize the style:By default, the template tag only outputs the HTML structure of **.You need to design the overall website, and add styles to the friend link list through CSS, such as font, color, layout, etc., to ensure that they are beautiful and easy to read.
  3. Quantity control:Although friend links are beneficial, more is not necessarily better. Too many friend links may dilute page authority and may even be considered as a cheating behavior by search engines.It is recommended to maintain a moderate quantity and prioritize high-quality, relevant links.

By following these steps and code examples, you should be able to easily retrieve and display the friend link list in the AnQiCMS template, adding more value to your website.


Frequently Asked Questions (FAQ)

  1. Why have I added a friend link in the background, but it doesn't show on the website front end?

    • Please check if you have used the template file correctlylinkListtags, and within the tags,{% for ... %}Loop is also correctly written.
    • Confirm that your友情 link is enabled in the background.
    • Check if the template file contains similar{% if friendLinks %}Such a conditional statement, if the list is empty, this code may cause the entire friend link area not to display.
    • If there is a cache on the page, try to clear the system cache of AnQiCMS.
  2. How to make a friendship link open in a new window (new tab)?

    • Before your<a>the tag withtarget="_blank"Just attributes. For example:<a href="{{item.Link}}" target="_blank">{{item.Title}}</a>The example code provided in this article already includestarget="_blank".
  3. Can I display the remarks filled in by the administrator in the background next to the友情 links?

    • Yes. Each item in the友情 links includesitem.Remarkfield. You just need to<a>near the tag, use{{item.Remark}}To display note information. For example:<li><a href="{{item.Link}}" target="_blank">{{item.Title}}</a> {% if item.Remark %}<span class="link-remark">({{item.Remark}})</span>{% endif %}</li>.