In website operation, friendly links are not only the bridges between websites, but also one of the important strategies to enhance website authority, increase external traffic, and optimize search engine rankings.Reasonable configuration and display of友情链接 can effectively improve the website's SEO performance, while providing users with more valuable external resources.AnQiCMS as an efficient content management system, fully considers this requirement, and provides a simple and intuitive way to manage and display friend links in the front-end template.

Backend management: Setting and maintenance of friend links

You can navigate to the "Function Management" module from the backend, then find the "Friend Link Management". Here, you can easily add, edit, or delete friend links, and set the name, URL, notes, and whether to add for each link.nofollowProperty information.nofollowThe setting of properties is particularly important, as it helps you control the relationship between the website and external links, avoid unnecessary SEO risks, and ensure link quality.

Front-end Display: How to call the friend link through template tags

Once the friend link has been set up in the background, the next step is how to display them in the website's frontend template.AnQiCMS uses a syntax similar to Django template engine, allowing dynamic data calls with concise template tags.linkListThis tag can help us easily get all the configured friend link data.

To display friend links on your website template, you can place the following code snippet at the desired location, such as the footer of the website (footer.html) or in the sidebar (sidebar.html):

{% linkList friendLinks %}
{% if friendLinks %}
<div class="friendly-links-section">
    <h3>友情链接</h3>
    <ul class="friendly-links-list">
        {% for item in friendLinks %}
        <li class="link-item">
            <a href="{{ item.Link }}"{% if item.Nofollow == 1 %} rel="nofollow"{% endif %} target="_blank">{{ item.Title }}</a>
            {% if item.Remark %}<span class="link-remark">({{ item.Remark }})</span>{% endif %}
        </li>
        {% endfor %}
    </ul>
</div>
{% endif %}
{% endlinkList %}

Let's take a detailed explanation of this code:

Firstly,{% linkList friendLinks %}Is the core tag for calling friendship links. It retrieves all the configured friendship link data from the AnQiCMS background and stores these data in a namedfriendLinksThe variable is provided for subsequent use.{% endlinkList %}It marks the end of the call to this tag.

Next,{% if friendLinks %}The statement is a conditional judgment, it checksfriendLinksAre there actual data in the variable. This is a good programming habit that can avoid displaying an empty area on the page when there is no friendship link, thereby enhancing the user experience.

If there is a link, the code will enter adivcontainer, you can usually add some CSS classes (such asfriendly-links-section) for style control. Among them<h3>友情链接</h3>This is a title, you can modify or remove it according to your needs.

The core display logic is in{% for item in friendLinks %}a loop. This loop will traversefriendLinksEach friendship link in the list, on each iteration, assigns the data of the current link toitema variable.

Inside the loop,<li>An element is used to wrap a single friendship link.item.LinkThe URL address obtained is the one you set as a friend link in the background,item.Titlewhich is the display name of the link.

Especially pay attention to the fact that{% if item.Nofollow == 1 %} rel="nofollow"{% endif %}This code. It will automatically add the HTML tag based on whether you have checked the 'nofollow' option for this link in the backgroundrel="nofollow"Property. This is crucial for informing search engines not to follow this link and pass on weight, which helps maintain the SEO health of your website.target="_blank"The property is a common practice, which will make the friendship link open in a new window or a new tab, avoiding users from leaving your website.

Finally,{% if item.Remark %}<span class="link-remark">({{ item.Remark }})</span>{% endif %}Allow you to display the note information added to the link in the background, which is very useful for friendship links that require additional explanations.

Flexible use and precautions

This code provides the core data call logic.Regarding the style and layout of the友情链接 (Friendship Link), you can beautify and adjust it according to the overall design of the website, for example, setting the link color, font size, list spacing, and so on.

If you are using the multi-site management feature of AnQiCMS and want to call the friend links of other sites,linkListtag.siteIdparameters, such as{% linkList friendLinks with siteId="2" %}Here,"2"represents the ID of the target site you want to call.

Provided by AnQiCMSlinkListTags and flexible template syntax make it very simple and efficient to display friendly links.This can not only help optimize the SEO performance of your website, but also provide users with a better navigation experience.


Common Questions (FAQ)

1. What is the role of the link attribute? When should I use it?nofollow属性有什么作用?我应该在什么时候使用它?

nofollow