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 one
if 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. - Utilize
item.Nofollow == 1determination, dynamically adds links forrel="nofollow"Attribute, which is very important for SEO management of external links. - to
item.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
- 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. - 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.
- Note
nofollowproperty: 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. - 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