As an experienced website operations expert, I know that how to flexibly use template tags to display content in such an efficient content management system as AnQiCMS is the key to improving website operation efficiency.Friend links are an indispensable part of website external communication and SEO optimization, and their dynamic display often requires us to accurately obtain the text names of each link from the loop output.Today, let's delve deeply into how to elegantly implement this feature in AnQiCMS.


Unlock AnQi CMS友情链接: Easily obtain the text name (Title) of each link

In today's internet environment, friendship links (also known as external links) are still an indispensable part of the website content ecosystem and search engine optimization (SEO) strategy.They are not only bridges for transmitting trust between websites but also ways for users to find more related resources.For website operators using AnQiCMS to manage the operation, flexibly controlling the display of friendship links, especially the cyclic output of each link's text name, is a very practical skill.AnQiCMS powerful template tag system makes this task extremely simple and intuitive.

Core tool:linkListThe charm of tags

We need to bring out our core tool to loop output the friend links in the AnQiCMS template.linkListLabel. This label is specifically used to obtain the list of friend links configured on the background.Its usage is very concise and clear, allowing you to assign the collection of obtained friendship links to a variable, and then process them one by one through a loop.

Generally, you would start your friend link display area in the template:

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

Here, friendLinksThat is the variable name we specify for the collection of friend links. Once this tag is parsed,friendLinksVariables carry all the data of the link friendship, waiting for us to further "review."

Reveal the identity of the link: Get the text name (Title)

When you use{% for item in friendLinks %}Traverse such a loop statementfriendLinksWhen a set,itemThe variable represents an independent friendship link object in each iteration. ThisitemThe object contains all the details of the link, including its text name, link address, notes, and whether it has been setnofollowattributes, etc.

To get the text name of each link, which is itsTitleAttribute, you just need to access it easilyitemthe object'sTitleField, just like this:{{ item.Title }}.

Let's see how it works with a simple example:

{% linkList friendLinks %}
    <div class="friendship-links-section">
        <h4>我们的合作伙伴</h4>
        <ul>
            {% for item in friendLinks %}
                <li>链接文字名称: {{ item.Title }}</li>
            {% endfor %}
        </ul>
    </div>
{% endlinkList %}

This code will iterate through all the links and output the text name of each link.

Beyond the text: Get more link attributes

Except for the text nameTitle,itemThe object also provides several very useful properties, allowing you to build a friendship link display with more features according to your needs:

  • item.Link: The actual URL address of the friendship link.
  • item.Remark: Link remark information, usually as<a>label'stitleAttribute, providing a tooltip when the mouse hovers over
  • item.Nofollow: A boolean value (or equivalent number 1/0), indicating whether the link has been setrel="nofollow"Property. This is very important for SEO, as it can control whether the search engine tracks the link.

Combine these properties, and we can create a more functional and SEO-friendly friend link list:

{% linkList friendLinks %}
    <div class="friendship-links-section">
        <h4>我们的合作伙伴</h4>
        <ul class="footer-links-list">
            {% for item in friendLinks %}
                <li>
                    <a href="{{ item.Link }}"
                       {% if item.Nofollow == 1 %} rel="nofollow"{% endif %}
                       title="{{ item.Remark|default:item.Title }}" {# 如果没有备注,则使用Title作为提示 #}
                       target="_blank">
                        {{ item.Title }}
                    </a>
                </li>
            {% endfor %}
        </ul>
    </div>
{% endlinkList %}

In this example, we not only obtain the text name of the link{{ item.Title }}still according toitem.NofollowThe value dynamically addedrel="nofollow"attributes, and make use ofitem.Remarkto provide a better user experience for links.target="_blank"then make sure that the link opens in a new window to avoid users leaving the current website.

Gracefully handle the case when there are no friendship links

In some cases, your website may not have added any friendship links yet. To avoid blank pages or errors, you can useforin the loop{% empty %}Provide a fallback content block:

{% linkList friendLinks %}
    <div class="friendship-links-section">
        <h4>我们的合作伙伴</h4>
        <ul class="footer-links-list">
            {% for item in friendLinks %}
                <li>
                    <a href="{{ item.Link }}"
                       {% if item.Nofollow == 1 %} rel="nofollow"{% endif %}
                       title="{{ item.Remark|default:item.Title }}"
                       target="_blank">
                        {{ item.Title }}
                    </a>
                </li>
            {% empty %}
                <li>当前暂无友情链接,敬请期待!</li>
            {% endfor %}
        </ul>
    </div>
{% endlinkList %}

Even if no friend links are configured on the backend, the front-end page can still display a prompt message to enhance the user experience.

Summary

The template tag design of AnQiCMS makes tasks like obtaining the text name of a friend link very direct and efficient. ThroughlinkListtags, with the help offorloop anditem.TitleYou can easily access properties and dynamically display and manage friend links at any location on the website.This flexibility not only simplifies front-end development, but also provides strong support for the daily operation of the website and SEO strategy.Master these basic operations and you will be able to better utilize the various functions of AnQiCMS, creating a high-quality website with complete features and user-friendly interface.


Frequently Asked Questions (FAQ)

Q1: I added a friend link in the background, but it didn't show up on the front page. What's the matter? A1:This question usually has several reasons. First, make sure you have used the template correctly.{% linkList friendLinks %}and{% for item in friendLinks %}Such a label structure to traverse and display links. Next, check whether you have correctly added and saved the link in the background "Function Management" -> "Friend Links".Finally, if your website has caching enabled, please try clearing the AnQiCMS system cache to ensure that the latest data is loaded.

Q2: Can I control the display order of friendship links? For example, by publication time or custom sorting? A2:AnQiCMS'linkListLabels are usually sorted according to the default sorting of the friend link in the background management interface (such as ascending order by ID or the priority set by the background). CurrentlylinkListThe label itself does not provide directly.orderThe parameters are used to define the sorting logic of the front-end output. If you need a specific sorting, you may need to adjust the order of adding friend links in the background or use some front-end JavaScript for a second sorting after the page is loaded, but this will increase the complexity of front-end rendering.

Q3: Why do I want to add some friendship links without passing weight?rel="nofollow"How to operate in AnQiCMS? A3: rel="nofollow"The attribute tells the search engine not to follow the link and not to pass the "weight" or "trustworthiness" to the target website of the link.This is usually used for sponsor links, ad links, or external links whose content quality you are unsure of, to avoid affecting the SEO performance of your own website.When managing friend links in the AnQiCMS background, you can set each link individually whether it is enabled or notnofollow. In the template, as shown in the article example, you can{% if item.Nofollow == 1 %} rel="nofollow"{% endif %}This condition judgment is used to dynamically add this property.