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.