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

Friend link management: starting from the background

Before starting the template call, make sure that your website's background has already configured the friend links. The friend links management function of Anqi CMS is located atFunction ManagementModule under.Here, you can add new friendship links, edit the information of existing links, including the link name (Title), target address (Link), a brief remark (Remark), and whether to enable the 'nofollow' attribute (Nofollow).

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

These are the friendship links configured in the background, which are the data sources 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 for obtaining and displaying the backend-configured friend links on your website's frontend.This label is designed to be very intuitive, allowing you to easily integrate link data into any template position.

The basic syntax is as follows:

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

Here,变量名称is a name you customize, used to store the list of friend links, for examplefriendLinks.linkListThe label will retrieve all enabled friend links and assign them as a list object to the variable you specify.

Detailed explanationlinkListUse of tags

Due tolinkList标签会将友情链接作为一个列表(或称数组)返回,因此,您需要使用AnQiCMS模板引擎提供的forLoop through and display each link in the friendship links.

Each friendship link item includes the following available information:

  • item.Title: The display name of the friendship link.
  • item.LinkThe target URL address of the友情链接 link.
  • item.Remark:Friendship link remark information, usually used for brief descriptions or tips.
  • item.Nofollow:A boolean value (or 0/1 number), indicating whether the link has been set.rel="nofollow"Attribute. Whenitem.NofollowWhen set to 1, it indicates that it has been set.

Below is a complete code example demonstrating how to retrieve and display the friend link 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 file)partial/footer.htmlor the sidebar filepartial/sidebar.htmlIn English, after saving, you can see the effect on the front end.You can enhance the display effect of the friend link by modifying the HTML structure and adding CSS styles, making it consistent with your website design style.

in a multi-site scenariositeIdParameters

If you are using the multi-site management feature of AnQiCMS and want to call the friend link list in a template of a specific site,other sitesyou can do so by:siteIdThe parameter to implement. For example, if you want to call the friend link of a 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 fetching the current site's友情链接(friend links).

Considerations for integrating the友情链接(friend links) into the template.

  1. Location Selection:The most common location of友情链接is the website's footer, sidebar, or an independent “友情链接” page.Choose a location that is friendly to both users and search engines.
  2. Style Customization:By default, template tags only output the HTML structure of **.You need to add styles to the friend links list based on the overall design of the website using CSS, such as fonts, colors, layout, etc., to ensure they are aesthetic and easy to read.
  3. Quantity control:Although friendship links are beneficial, more is not always better.Too many friend links may scatter the page weight and even be considered as cheating behavior by search engines.Suggest to maintain a moderate amount and prioritize high-quality, highly relevant links.

Through the above steps and code examples, you should be able to easily obtain and display the friend link list in the AnQiCMS template, adding more value to your website.


Common Questions (FAQ)

  1. Why is the friendship link I added in the background not displayed on the website front end?

    • Please check if you have used the template file correctly.linkListTags, and the content within the tags,{% for ... %}The loop is also correctly written.
    • Confirm that your友情链接 friendship link is enabled in the background.
    • Check if your template file contains something similar{% if friendLinks %}Such a judgment 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 AnQiCMS system cache.
  2. How to open the friend link in a new window (new tab)?

    • In your<a>tag.target="_blank"Attribute. For example:<a href="{{item.Link}}" target="_blank">{{item.Title}}</a>The sample 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 friend link?

    • Sure. Each item of the friend link containsitem.Remarkfield. You just need to use<a>near the tag,{{item.Remark}}Show 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>.