How to retrieve and loop output friend links in AnQi CMS template?

Calendar 👁️ 49

Managing and displaying friend links in Anqi CMS is an important task in website operation, it not only helps to improve the quality of external links on the website and enhance the search engine optimization performance, but also provides users with more valuable resources.As an experienced website operator familiar with AnQiCMS, I will explain in detail how to obtain and loop output the friendship links in the AnQiCMS template.

Understanding the importance of friend links and the template mechanism of AnQiCMS

Friendship Links are a form of mutual recommendation between websites, usually appearing in the bottom or sidebar of a website in the form of text or image links.High-quality friendship links can help websites pass on weight, increase traffic entries, and improve user experience.AnQiCMS as an efficient content management system provides an intuitive backend management interface for adding, editing, and deleting friend links, and makes it easy to display the front-end through its flexible template tag system.

AnQiCMS's template system is based on a syntax similar to the Django template engine, using{{变量}}to output variable content, as well as{% 标签 %}Come to handle logical control, such as conditional judgment and loop. All template files are under.htmlsuffix and stored in/templatedirectory. Understanding this basic mechanism is the foundation for successfully implementing the circular output of friendship links in templates.

UselinkListTag to get friend link data

AnQiCMS provides a special template tag for obtaining friend link data——linkList. This tag can easily retrieve all configured friendship links from the background database.

While usinglinkListWhen labeling, it is usually assigned to a variable, for example,friendLinksThis variable will be an array object containing all the友情链接 links.linkListThe basic usage of the tag is as follows:

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

linkListThe tag also supports an optional parameter.siteId. If you have enabled the multi-site management feature in the AnQiCMS backend and want to get the friendship links of a specific site, you can specifysiteIdTo complete. But for most single-site cases, this parameter can be omitted, the system will automatically obtain the friend links of the current site.

In{% linkList friendLinks %}and{% endlinkList %}You can access between these tags.friendLinksVariable. BecausefriendLinksis an array object, you need to useforloop to traverse each friend link item

loop to output the detailed steps of the friend link

Now, let's build the code step by step to output friend links in the template:

Firstly, determine the position where you want the友情链接 (friendship link) to be displayed. This is usually in the footer (footer.html), sidebar (sidebar.html), or a dedicated "friendship links" page.Suppose we want to display friend links in the footer.

Next, in the corresponding template file (such as)partial/footer.htmlinsert in thelinkListLabel, and name the link list obtainedfriendLinks:

<div class="friendship-links">
    <h3>友情链接</h3>
    <ul>
        {% linkList friendLinks %}
            {# 友情链接列表将在这里生成 #}
        {% endlinkList %}
    </ul>
</div>

To ensure that the entire block is displayed only when there is friend link data, we can add aif friendLinksThe condition judgment, so as to avoid displaying empty titles and list structures when there are no links, enhancing the robustness of the template:

<div class="friendship-links">
    {% linkList friendLinks %}
        {% if friendLinks %} {# 检查 friendLinks 数组是否为空 #}
            <h3>友情链接</h3>
            <ul>
                {# 友情链接列表将在这里生成 #}
            </ul>
        {% endif %}
    {% endlinkList %}
</div>

Then, in<ul>Use within the tag, forLoop throughfriendLinksarray. In each iteration, a nameditemThe variable will represent the current friendship link object. You can visititemdifferent properties of the object to get the link details:

  • item.Title: The display name of the link.
  • item.Link: The target URL address of the link.
  • item.Remark: The remark information of the link.
  • item.NofollowA boolean value (or 1/0), indicating whether it needs to be addedrel="nofollow"Property.

Combining these properties, we can construct the HTML structure for each link:

<div class="friendship-links">
    {% linkList friendLinks %}
        {% if friendLinks %}
            <h3>友情链接</h3>
            <ul>
                {% for item in friendLinks %}
                    <li>
                        <a href="{{ item.Link }}" {% if item.Nofollow == 1 %} rel="nofollow"{% endif %} target="_blank">{{ item.Title }}</a>
                    </li>
                {% endfor %}
            </ul>
        {% endif %}
    {% endlinkList %}
</div>

In this code snippet:

  • href="{{ item.Link }}"Set the target address of the link.
  • {% if item.Nofollow == 1 %} rel="nofollow"{% endif %}Is a conditional judgment, if the background is set to this linknofollowThen add the corresponding attribute on the front end. This is very important for controlling the flow of page weight and meeting search engine standards.
  • target="_blank"Generally used for friendship links, ensuring that the link opens in a new tab to avoid users leaving the current website.
  • {{ item.Title }}Displays the text content of the link.

By following these steps, you can retrieve and flexibly loop out the friendship links in the AnQiCMS template.

Operation considerations and **practice**

When displaying友情链接 (friendship link) in a template, in addition to technical implementation, it is also necessary to consider some operational and SEO practices:**

  1. Link qualityAlways prioritize exchanging friendship links with websites that are relevant to the content, have high weight, and are updated actively. Avoid establishing links with bad websites or websites with unhealthy content.
  2. nofollowApplication of propertiesFor some links whose content quality you are not sure of, but still need to display, or pure advertising links, userel="nofollow"You can tell the search engine not to track the link to avoid negative impact on the SEO of your website.The AnQiCMS backend provides this feature, and the template also includes the corresponding judgment.
  3. Layout and user experience: Friend links are usually placed at the bottom of the website or in less prominent positions to avoid distracting from the main content. Ensure that the link text is clear and readable, with enough contrast between the color and the background.
  4. Regular maintenance: Friend links need to be checked regularly. Websites may be redesigned, closed, or links may become invalid.Keep outdated or broken links updated or deleted, which helps maintain the professionalism of the website and the friendliness to search engines.

MasteredlinkListHow to use tags, combined with appropriate operational strategies, your AnQiCMS website will be able to better manage and utilize the friendship link resources.


Frequently Asked Questions (FAQ)

1. I added a friend link in the background, why doesn't the front page show it?

There may be several reasons: First, please check if you have added the above code to the correct template file, such as the footer or sidebar template of your website. Second, confirm the variable names used in your template file (such asfriendLinks) and{% linkList %}The names defined in the tags are consistent. Finally, please clear the website cache in the "Update Cache" function of the AnQiCMS backend, as cache sometimes causes new content to not be displayed on the front page in time.

2. Where is the AnQiCMS backend to manage friend links?

On the AnQiCMS backend management interface, you can find the 'Function Management' module through the left navigation menu.Click to enter, and there will usually be a submenu item named "Friend Links".Here, you can add new友情 links, edit the name, URL, and whethernofollowand sorting information.

3. Can I display different categories of friend links at different locations in AnQiCMS, such as "Partners" and "Personal Blogs"?

According to the current AnQiCMS documentation,linkListThe label does not provide direct filtering by 'grouping' feature.It will fetch all the background-configured friend links. If you need to display links of different categories, you can consider the following alternative methods:

  • the background management levelIn the "Notes" field of the friendship link in the background, add a category identifier for each link (such as "Partner" or "Personal Blog"). Then, after obtaining all the links in the template, useifConditional judgmentitem.RemarkField to manually filter and output to different HTML areas.
  • Custom field/tag: If the system supports it, you can also consider adding custom fields for friendship links to distinguish between groups, and control more flexibly through advanced template logic, but this may require deeper knowledge of template development or the secondary development capabilities of AnQiCMS.

Related articles

How to get and display website name, Logo, filing number and other system information in AnQi CMS template?

As an experienced Anqi CMS website operation personnel, I am well aware of the importance of efficiently obtaining and displaying website system information in templates.This not only concerns the user experience of the website, but is also the foundation of SEO optimization and brand image building.AnQiCMS provides a simple and powerful template tag system that allows developers and operators to easily present various core information of the website on the front page.

2025-11-06

How to install and manage multiple sites on a single server in AnQi CMS?

As an expert in Aqin CMS content management and website operation, I fully understand the value of efficient management of multiple sites.The multi-site management function of AnQi CMS is specifically designed to meet this core requirement, allowing for the management and operation of multiple independent websites on a single server with a streamlined and efficient architecture.This has greatly improved operational efficiency and effectively integrated resources. ### Understanding the Multi-Site Architecture of AnQi CMS AnQi CMS does not require the installation of a separate program for each website.

2025-11-06

How to configure the pseudo-static rules in AnqiCMS to optimize the website URL structure?

As an experienced person who deeply understands the operation of AnQiCMS, I know that an optimized URL structure is crucial for the long-term development of a website.It not only significantly improves the user experience, allowing visitors to clearly understand the website content, but also plays a core role in search engine optimization (SEO), directly affecting the ranking and visibility of the website in search results.The pseudo-static function of AnqiCMS is the important tool we use to achieve this goal.

2025-11-06

What search engines does AnqiCMS support for active link push function?

As a website operator who deeply understands the operation of AnQiCMS, I know that timely inclusion after content publication is crucial for website traffic and SEO performance.AnQiCMS provides powerful support in this field, especially its link push function, which can effectively shorten the time from publication to being discovered by search engines.### AnQiCMS Link Push Function Overview AnQiCMS's built-in link push function is an important part of its advanced SEO toolkit.

2025-11-06

The AnqiCMS comment management feature, does it support liking and replying operations?

As an experienced security CMS website operation person, I know that content is the soul of the website, and user interaction is an important manifestation of the vitality of the content.AnQi CMS provides rich and powerful features in content management, among which comment management is a key link to build the community and enhance user stickiness.Today, I will elaborate on the comment management function of Anqi CMS to discuss whether it supports like and reply operations.

2025-11-06

How to use the pagination tag in the AnqiCMS template to implement pagination display of document lists?

As an experienced CMS website operation personnel of an information security company, I fully understand that how to effectively display content is the key to attracting and retaining users when building and maintaining a website.Especially for pages such as document lists that may contain a large amount of information, a reasonable pagination mechanism not only improves user experience but also optimizes website performance.Today, I will elaborate on how to use the pagination tag in AnqiCMS templates to implement pagination of document lists.

2025-11-06

How to flexibly use the `if`, `for` and other logical judgment and loop tags in AnqiCMS template development?

As a professional deeply familiar with AnqiCMS operations, I know that template development is the core link in building a website with attractive appearance and complete functions.During the process of content creation, editing, and publishing, flexibly using logical judgments and loop tags in template languages can make our website content dynamically presented and adaptable to diverse business scenarios, thereby better meeting the needs of readers and improving user experience.Today, let's delve into the flexible application of logical tags such as `if`, `for`, and others in AnqiCMS template development.

2025-11-06

How to implement string processing and content-safe output for AnqiCMS filters (such as `safe`, `truncatechars`)?

As an experienced CMS website operation personnel for an enterprise, I know the importance of content quality and safe output for the success of the website.In daily content management, we often need to format text to ensure its beauty and readability on the front-end interface.At the same time, the secure output of content is the cornerstone that we cannot ignore, as it is directly related to user experience, website reputation, and even legal compliance.The AnQi CMS provides a powerful and flexible template filter mechanism to help us easily cope with these challenges.

2025-11-06