In the operation of a website, friendship links are an important means to enhance website authority, increase external traffic, and promote cooperative relationships.A convenient and flexible friend link feature is crucial for any content management system.AnQiCMS as an efficient content management system, provides an intuitive way to manage and retrieve the list of links in the template.

This article will introduce in detail how to obtain and loop through the website's friend link list in AnQiCMS template, helping you easily achieve interconnection between websites.

AnQiCMS Overview of Friend Links Function

In AnQiCMS, the management of friend links is very intuitive and efficient.You can find the 'Friend Links' option under the 'Feature Management' menu in the background, where you can conveniently add, edit, or delete individual friend links.nofollowAttributes, which are especially helpful for SEO optimization.

These friendship link data configured in the background need to be displayed in the website's front-end template, for visitors to click.AnQiCMS provides a special template tag that allows you to easily display this data on the page.

The core of the template:linkListtags

We need to use the built-in AnQiCMS to call these carefully set友情链接 in the template.linkListTags. This tag is used to retrieve all the link data of the website and provide it as a list available for iteration to the template.

linkListThe basic usage of the tag is as follows:

{% linkList friendLinks %}
    {# 在这里处理友情链接列表 #}
{% endlinkList %}

Among them,friendLinksThis is a variable name we give to the list of友情链接 (friendship links) we obtain. You can name it according to your preference. This variable name will be used inside the tag to refer to the friendship link data.

In most cases, you do not need tolinkListSet any parameter for the label, and the system will automatically retrieve the current site's friend links. But if you have enabled the multi-site management feature in AnQiCMS and need to retrieve friend links from other sites, you cansiteIdSpecify the parameter, for example:{% linkList friendLinks with siteId="1" %}where,"1"Represents the ID of the target site.

Step-by-step operation: get and loop output the friend links

Get and loop output the friendship link mainly involves two steps: the first is to uselinkListlabel to get data, and then it is to useforloop through the data and build the HTML structure.

Step one: uselinkListLabel data acquisition

As described above, first in the template location where you want to display the friend link (usually in the footer or other sidebar area), uselinkListtags to wrap your code block.

{% linkList friendLinks %}
    {# 循环输出友情链接的代码将放在这里 #}
{% endlinkList %}

If your website currently has no friendship links,friendLinksThe variable will be an empty list. When looping, you can choose to handle this situation, for example, displaying a message such as 'No friendship links available'.

Step two: Traverse the friendship link data and build the HTML structure

Get tofriendLinksAfter the list, we can use the AnQiCMS template engine'sforLoop tags to iterate over and output the detailed information of each friendship link one by one.

Inside the loop, each friendship link data will be assigned to a temporary variable (for example)item). ThroughitemYou can access various properties of the friendship link, such as:

  • item.Title: The display name of the friendship link.
  • item.Link: The complete URL address of the friendship link.
  • item.Remark[en] The remark information set in the background (if needed to be displayed).
  • item.Nofollow[en] A boolean value indicating whether the link is set in the background as.nofollow(1[en] Indicates yes.0[en] Indicates no.).

Combining these properties, we can construct a standard HTML friends link list:

{% linkList friendLinks %}
    {% if friendLinks %} {# 判断是否有友情链接,避免空列表也输出容器 #}
    <div class="footer-links">
        <h3>友情链接</h3>
        <ul>
        {% for item in friendLinks %}
            <li>
                <a href="{{item.Link}}"
                   {% if item.Nofollow == 1 %}rel="nofollow"{% endif %}
                   target="_blank"
                   title="{{item.Remark}}">
                    {{item.Title}}
                </a>
            </li>
        {% endfor %}
        </ul>
    </div>
    {% else %}
    <p>暂无友情链接。</p>
    {% endif %}
{% endlinkList %}

In the above code example, we have made some optimizations:

  • We have used aif friendLinksEnsure that the entire container is output only when there is a friendship link, otherwise display the prompt "No friendship links available".
  • Added to the linktarget="_blank"Properties, ensure that it opens in a new window after clicking without affecting the user's current browsing.
  • Utilizeitem.Nofollow == 1judgment, dynamically adding to the link.rel="nofollow"Properties, which is very important for SEO management of external links.
  • toitem.RemarkastitleProperty added to<a>Tag, which can display more information when the user hovers over it.

Complete code example

Integrate the above steps, and the following is an example of a complete and practical template code for a friendship link list:

{# 在您希望显示友情链接的模板文件中粘贴以下代码,例如 footer.html #}

{% linkList friendLinks %}
    {% if friendLinks %}
    <div class="friendship-links-section">
        <h3 class="section-title">合作伙伴与友情链接</h3>
        <ul class="links-list">
        {% for item in friendLinks %}
            <li class="link-item">
                <a href="{{ item.Link }}"
                   {% if item.Nofollow == 1 %}rel="nofollow"{% endif %}
                   target="_blank"
                   title="点击访问 {{ item.Title }}{% if item.Remark %} - {{ item.Remark }}{% endif %}">
                    {{ item.Title }}
                </a>
            </li>
        {% endfor %}
        </ul>
    </div>
    {% else %}
    <div class="friendship-links-section">
        <p class="no-links-message">我们正在积极拓展合作,友情链接即将上线,敬请期待!</p>
    </div>
    {% endif %}
{% endlinkList %}

{# 您可以根据需要为 .friendship-links-section, .section-title, .links-list, .link-item, .no-links-message
等CSS类添加样式,以美化展示效果。 #}

This code not only effectively retrieves and displays your friendship links, but also considers friendly prompts when there are no links, as well as SEO-friendly attribute handling.nofollowAttribute processing.

Tips for optimizing the display of friendship links

  1. Style beautificationAlthough the code has provided the HTML structure, a beautiful display cannot be achieved without the enhancement of CSS.div/ul/liandaAdd appropriate styles to the tags to keep them consistent with the overall design style of your website, enhancing the user experience.
  2. Place them reasonablyThe "friend links" are usually placed at the footer area of a website or a dedicated "friend links" page. Choose the most suitable display position according to the type of your website and user habits.
  3. NotenofollowPropertyin the background managementnofollowoptions are very practical. For those external links you do not want to pass weight or are not completely trustworthy,nofollowCan avoid negative impact on your website's SEO.
  4. Regular maintenanceRegularly check the validity of friendship links, delete expired links, update outdated information, and maintain link quality, which is crucial for the long-term healthy development of the website.

Through the concise template tags and flexible backend management of AnQiCMS, you can easily integrate the friendship link feature into your website, promote interconnectivity with other websites, and provide strong support for your content marketing and SEO strategy.


Common Questions (FAQ)

Q1: I added a friend link in the AnQiCMS admin backend, but it's not showing on the front page. What's the matter?A1: If the background has successfully added and saved the friendship link but it is not displayed on the front-end, please check if your template file has used it correctly.{% linkList friendLinks %}...{% endlinkList %}Ensure that the tag has been used correctly.friendLinksVariables are correctly traversed in the loop. Additionally, please clear the AnQiCMS system cache, as the cache sometimes causes updates to be不及时.

Q2:rel="nofollow"What is the role of this attribute, and when should I use it?A2:rel="nofollow"It is an HTML attribute used to tell search engines not to