As an experienced website operation expert, I know that how to flexibly use template tags to display content in a high-efficient content management system like AnQiCMS is the key to improving website operation efficiency.友情链接作为网站对外交流和SEO优化不可或缺的一部分,其动态展示往往需要我们从循环输出中精准地获取每一个链接的文字名称。Today, let's delve into how to elegantly implement this feature in AnQiCMS.
Unlock AnQi CMS friend links: 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 SEO strategy.They are not only the bridges for trust transmission between websites, but also the ways for users to discover more related resources.For operators who use AnQiCMS to manage website operations, flexibly controlling the display of friend 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 tools:linkListThe charm of tags
We need to bring out our core weapon to loop through friend links in the AnQiCMS template,linkListLabel.This tag is specifically used to obtain the list of friendship links configured on the backend.Its usage is very concise and clear, allowing you to assign the collection of acquired 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 like this:
{% linkList friendLinks %}
{# 友情链接将在这里循环输出 #}
{% endlinkList %}
Here,friendLinksIt is the variable name we specify for the friend link collection. Once this tag is parsed,friendLinksThe variable carries all the data of the friendship links, waiting for us to further 'inspect'.
Reveal the identity of the link: obtain the text name (Title)
When you use{% for item in friendLinks %}Such a loop statement traversesfriendLinksWhen collecting,itemThe variable represents a separate friendship link object in each loop. ThisitemThe object includes all the details of the link, including its text name, link address, notes, and whether it is set.nofollowProperties, etc.
To get the text name of each link, that is, itsTitleProperties, you only need to access it simply.itemObjects'TitleFields, 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 over all friendship links and output the text name of each link.
Beyond the Text: Get More Link Properties
Besides the text nameTitle,itemThe object also provides several very practical properties, allowing you to build more feature-rich friendship link displays as needed:
item.Link: The actual URL address of the friendship link.item.Remark: English description of the linked note, usually usable as<a>TagstitleProperty, providing a tooltip on mouse hover.item.Nofollow: A boolean value (or equivalent number 1/0), indicating whether the link has been set.rel="nofollow"Properties. This is very important for SEO and can control whether the search engine tracks the link.
Combine these properties, and we can create a more functional and SEO-friendly 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 obtained the text name of the link{{ item.Title }}Englishitem.Nofollowthe value, dynamically addedrel="nofollow"Englishitem.RemarkEnglishtarget="_blank"English
The graceful handling of empty friend links
In some cases, your website may not have added any friend 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 %}
In this way, even if no friendship links are configured on the backend, the front-end page can display a friendly prompt message to enhance the user experience.
Summary
The template tag design of AnQiCMS makes tasks like getting the text name of friend links very direct and efficient. ThroughlinkListtags, withforloop anditem.TitleYou can easily display and manage friend links dynamically 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 make better use of AnQiCMS's various functions, creating high-quality websites that are feature-rich and user-friendly.
Common Questions (FAQ)
Q1: I added a friend link in the background, but the front-end page did not display. What's the matter?
A1:This question usually has several reasons. First, please make sure that you have used your template correctly.{% linkList friendLinks %}and{% for item in friendLinks %}This label structure is used to traverse and display links.Next, check if you have correctly added and saved the link in the background "Function Management" -> "Friend Links".Finally, if your website has caching enabled, please try to clear the AnQiCMS system cache to ensure that the latest data is loaded.
Q2: Can I control the display order of the友情链接 links? For example, by publication time or custom sorting?
A2:AnQiCMSlinkListLabels are usually sorted according to the default sorting of the友情链接 in the background management interface (such as ascending order by ID or priority set by the background). CurrentlylinkListLabels themselves do not provide directlyorderThe parameter comes from the custom sorting logic of the front-end output.If you need a specific sort, you may need to adjust the order of adding friend links in the background or use some front-end JavaScript to perform a second sort after the page is loaded, but this will increase the complexity of front-end rendering.
Q3: Why do I not want to pass weight for some friendship links and need to add?rel="nofollow"How to operate in AnQiCMS?
A3: rel="nofollow"属性告诉搜索引擎不要追踪该链接,也不要将“权重”或“信任度”传递给链接的目标网站。This is usually used for sponsored links, advertising links, or external links whose content quality you are uncertain about, to avoid affecting the SEO performance of your own website.nofollow. In the template, as shown in the article example, you can go through{% if item.Nofollow == 1 %} rel="nofollow"{% endif %}Such conditional judgment to dynamically add this property.