How to retrieve and loop the list of friend links in the AnQiCMS template?

Calendar 👁️ 64

In website operation, friendship links are an important means to enhance website authority, increase external traffic, and promote cooperative relations.A convenient management and flexible display of友情链接 links feature is crucial for any content management system.AnQiCMS as an efficient content management system provides an intuitive way to manage and obtain the list of friend links in templates.

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

Overview of the Friendship Link Function in AnQiCMS

In AnQiCMS, the management of friend links is very intuitive and efficient.You can find the 'Friend Links' option under the 'Function Management' menu in the background, where you can conveniently add, edit, or delete each friend link.Each friendship link can be set to have a name, link address, note, and even can flexibly choose whether to add itnofollowProperties, which are particularly 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:linkListTag

We need to use AnQiCMS built-in to call these carefully set friendship links in the templatelinkListThe tag is used to retrieve all the friendship link data on the website and provide it as a list available for iteration to the template.

linkListThe basic usage of tags is as follows:

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

Among them,friendLinksThis is the variable name given to the friend link list we obtain, you can name it according to your habit. This variable name will be used within the tag to refer to the friend link data.

In most cases, you do not need tolinkListSet any label parameters, the system will automatically retrieve the friend links of the current site. 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" %}of which"1"Represents the ID of the target site.

Step by step operation: Get and loop output the friendship link

Get and loop to output the main link of friendship is divided into two steps: the first is to uselinkListtag to get data, then to useforLoop through the data and build the HTML structure.

Step one: uselinkListLabel to retrieve data

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

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

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

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

obtaining tofriendLinksAfter the list, we can use the AnQiCMS template engine'sforTranslate the loop tag to iterate and output the detailed information of each friendship link.

Inside the loop, each friendship link data is assigned to a temporary variable (for exampleitem)。ByitemYou can access various properties of the friend link, such as:

  • item.Title: Display name of the friend link.
  • item.Link: The complete URL address of the friend link.
  • item.Remark: Remarks set in the background (if needed to be displayed).
  • item.NofollowA boolean value indicating whether the link is set in the backgroundnofollow(1indicating yes,0means no).

Combining these properties, we can build a standard HTML friendship 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 made some optimizations:

  • Used oneif friendLinksDetermine whether to output the entire container only when there is a friendship link, otherwise display the prompt "No friendship links available.".
  • Added to the link.target="_blank"Attribute, ensure that it opens in a new window after clicking without affecting the user's current browsing.
  • Utilizeitem.Nofollow == 1determination, dynamically adds links forrel="nofollow"Attribute, which is very important for SEO management of external links.
  • toitem.Remarkastitlethe attribute to<a>In the label, more information can be displayed when the user hovers over the mouse.

Complete code example

Integrate the above steps, and here 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 can effectively retrieve and display your friend links, and also considers friendly prompts when there are no links, as well as SEO-friendly attribute processing.nofollowAttribute processing.

Tips for optimizing the display of friend links

  1. Style beautificationAlthough the code has provided the HTML structure, beautiful display cannot be achieved without the addition of CSS.div/ul/liandaAdd the appropriate style to the label to keep it consistent with the overall design style of your website and enhance the user experience.
  2. Place reasonably: Friend links are usually placed in the footer area of a website or on a dedicated "Friend Links" page. Choose the most suitable display location based on the type of your website and user habits.
  3. Notenofollowproperty: In the background managementnofollowoptions are very practical. For those external links you do not want to pass weight or do not fully trust, setnofollowit can avoid having a 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 simple template tags and flexible backend management of AnQiCMS, you can easily integrate the friend link feature into your website, promote interconnectivity with other websites, and provide strong support for your content marketing and SEO strategy.


Frequently Asked Questions (FAQ)

Q1: I added a friend link in the AnQiCMS backend, but it did not display 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 whether your template file has used it correctly.{% linkList friendLinks %}...{% endlinkList %}tags and make surefriendLinksThe variable is traversed correctly in the loop. Additionally, please clear the AnQiCMS system cache, as cache can sometimes cause updates to be timely.

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

Related articles

How to get the complete content, SEO information, and associated images of a single page?

In daily website operations, independent pages such as "About Us", "Contact Information", etc., play an important role in conveying core information and shaping the brand image.As content operators, we often need to gain a deep understanding of the structure of these pages, including their main content, SEO information, and all associated image resources, in order to carry out fine management, optimization iteration, or flexible page layout.AnQiCMS provides an intuitive and powerful template tag system, making it easy to obtain these page data.

2025-11-08

How to get and loop through all independent pages in AnQiCMS template (such as About Us)?

In AnQi CMS, sometimes we need to list some independent pages in the website's navigation bar, footer, or other specific areas, such as "About Us", "Contact Us", "Privacy Policy", and so on.These pages usually contain fixed content and do not belong to a specific category or article model. AnQiCMS refers to them as 'single pages'.Fortunately, AnQiCMS provides a very intuitive and powerful template tag that can easily retrieve and loop through information for these single pages.### Core Tag

2025-11-08

How to display the main category in the navigation bar and show the latest products under this category in the dropdown menu?

In website operation, a clear and effective navigation system is the key to improving user experience and website professionalism.AnQiCMS (AnQiCMS) with its flexible content management and powerful template engine, can help us easily achieve complex navigation requirements.Today, let's discuss how to display the main categories in the website's navigation bar and also show the latest products under the category in a dropdown menu when the mouse hovers over it.### One, Understand the navigation and content management basics of AnQiCMS One of the core advantages of AnQiCMS lies in its modular content management system

2025-11-08

How to implement a multi-level nested tree structure display in the category list?

When building website categories, we often need to display a clear, hierarchical structure so that users can intuitively understand the ownership of the website content.AnQiCMS provides powerful template tag features, fully supporting the display of multi-level nested tree structures in category lists, helping you easily create a user-friendly navigation system.The core of achieving this effect lies in the clever use of the `categoryList` template tag of Anqi CMS and its built-in hierarchical judgment function.By looping in the template, you can use the parent-child relationship of the category

2025-11-08

How to retrieve and display the list of Banner carousel images configured on the website homepage?

In Anqi CMS, the Banner slideshow on the homepage is an important element to attract visitors' attention and display core content.Correctly obtain and display these banner images, which can greatly enhance the visual effects and user experience of the website.Anqi CMS provides intuitive functions and flexible template tags, allowing us to easily achieve this goal. ### First Step: Configure Your Banner Carousel in the Backend Before starting to display the Banner on the website frontend, we first need to configure it in the Anqi CMS backend management system. Typically

2025-11-08

How to display a list of articles with pagination and customize the style and number of pagination navigation pages?

Today, with the increasing richness of website content, how to efficiently display a large number of articles while ensuring a smooth browsing experience is a problem that every website operator needs to consider.AnQiCMS (AnQiCMS) provides a powerful and flexible article list pagination feature, which not only helps to optimize the content presentation of the website, but also allows for better integration into the overall website design through custom styles and page number settings, enhancing the user interaction experience.Next, we will delve into how to implement pagination of the article list in Anqi CMS

2025-11-08

How to dynamically add a website name suffix or custom delimiter in the page title (Title)?

The page title (Title) is the 'front door' of a website on the search engine results page. It not only can intuitively tell users the content of the page, but it is also an important indicator for search engines to evaluate the relevance and authority of the page.An optimized page title that can significantly improve click-through rates and the website's search engine ranking.In AnQiCMS, you can flexibly control the way page titles are generated, especially by dynamically adding the website name suffix and custom delimiters to achieve a unified brand image and better SEO effect.### AnQiCMS in TDK

2025-11-08

How to implement search through URL parameters (such as `q=keyword`) on the article list page and display the results?

It is crucial to provide users with a convenient and accurate content search experience in website content operation.When the number of articles on the website continues to grow, a practical search function can greatly enhance user satisfaction and the efficiency of content access.AnqiCMS as an efficient content management system provides a flexible way to implement the URL parameter search function for the article list page, allowing visitors to directly search and view related content by adding parameters such as `q=keywords` to the URL.

2025-11-08