How to effectively call and display the friend link list in templates when setting up and managing a website using AnQiCMS is a common and practical need.Friendship links can not only help improve the website's SEO performance but also provide users with more valuable external resources.AnQiCMS powerful template engine combined with its background functions makes this operation very direct.

Manage friend links: Start from the background

Before displaying the friendship link on the website front-end, we first need to set it up in the AnQiCMS backend.AnQiCMS provides a user-friendly link management feature, allowing you to easily add, edit, and manage your link list.

Log in to the AnQiCMS backend, find 'Function Management' in the left navigation bar, and then click on 'Friend Link Management'.Here, you can see the existing list of friendship links and can also add new links.

When you add a new friendship link, you usually need to fill in the following information:

  • Link nameThis is the name displayed on the website frontend for the friendship link, it should be concise and clear, and be able to clearly express the content of the link.
  • Link AddressThis is the complete URL that the friendship link points to, be sure to ensure its accuracy.
  • [en] NoteYou can enter some internal instructions here for easy management, which is usually not displayed on the front end.
  • The Nofollow attributeThis is a very important option.Check 'nofollow' to tell search engines not to follow this link and not to pass your website's authority to it.This is very useful for avoiding the impact of irrelevant links on your website's SEO, or when the content linked to is not entirely trusted.

After completing these settings, save the link, and it will be successfully added to your friend link library.

Call the friend link in AnQiCMS template

Set up the friend links on the backend, and the next step is to display them in the template on the website frontend.The AnQiCMS template system uses syntax similar to the Django template engine, providing dedicated tags for conveniently accessing data.

To display the list of friend links, we need to uselinkListthe tag. This tag is specifically designed to retrieve the friend link data configured in the background.

Its basic usage is:

{% linkList friendLinks %}
    {# 在这里放置循环代码来显示友情链接 #}
{% endlinkList %}

Here,friendLinksThis is a variable name you define, used to receive the data list of friend links within the tag.linkListThe tag will return an array (or slice) object containing all the friend link information, with each element representing a friend link.

We can throughforLoop to iterate through thisfriendLinksVariable, and display the detailed information of each link in turn. At the same time, in order to ensure that the HTML structure is rendered only when there are friendship links, we can useifcondition judgment.

Let's look at a specific example of how to organize code in a template to display a friend link:

{% linkList friendLinks %}
    {% if friendLinks %}
    <div class="footer-links">
        <h4>友情链接</h4>
        <ul>
            {% for item in friendLinks %}
            <li>
                <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 parse this code:

  • {% linkList friendLinks %}and{% endlinkList %}This is the start and end of calling the friendship link tag. It tells AnQiCMS to fetch the friendship link data and assign it tofriendLinksa variable.
  • {% if friendLinks %}This is a very practical judgment, it checksfriendLinksIs the list empty? Only when the background indeed adds friendship links, will it render the internal HTML structure, to avoid displaying empty titles or lists when there are no links.
  • <h4>友情链接</h4>and<ul>...</ul>This is the HTML structure we define for the friendship link list, you can adjust it according to your website's style requirements.
  • {% for item in friendLinks %}ThisforThe loop will iterate over thefriendLinksEach friendship link in the list. In each iteration, the data of the current link will be assigned toitema variable.
  • <li>...</li>: List item, used to carry information about a single friendship link.
  • {{item.Link}}This shows the current URL address of the friendship link.
  • {% if item.Nofollow == 1 %} rel="nofollow"{% endif %}This is a conditional judgment, if the link is set to 'nofollow' on the back-end, it will be automatically added here.rel="nofollow"Attribute. This is an important detail for SEO optimization.
  • target="_blank"[en]: This attribute is usually added to friend links to open them in a new tab, improving user experience and preventing visitors from leaving your website.
  • {{item.Title}}[en]: This shows the name of the current friend link.
  • {% if item.Remark %}<span class="link-remark">{{item.Remark}}</span>{% endif %}If the background has filled in a note for this link, it will be displayed here.

You can flexibly call and display the friend link list in the AnQiCMS template through such code structure.[en] Usually, friendly links are placed in the footer of a website or on an independent "Friendly Links" page.

Tips and **Practice

  1. Location of template fileUsually, the code snippet for the friendship link can be placedpartial/footer.htmlsuch public files, then through{% include "partial/footer.html" %}to reference in other templates, maintaining code modularity.
  2. Style beautificationThe above HTML code is just a basic structure, you can customize the CSS style to beautify the display of the link, making it consistent with the overall style of your website.
  3. Multi-site callsIf you have used the multi-site management feature of AnQiCMS and wish to call the friendship link of a specific site,linkListtag.siteIdparameters, such as{% linkList friendLinks with siteId="2" %}To specify the friendship links of the site with ID 2. However, for most single-site users, it is not necessary to specify this parameter.

By following these steps and techniques, you will be able to manage and display friend links skillfully in the AnQiCMS website template, adding a practical value to your website.


Common Questions (FAQ)

1. Ask: What is the use of the link attribute?rel="nofollow"Attribute?Answer:rel="nofollow"The attribute tells the search engine not to pass the "weight" or "trustworthiness" of your website to the page that this link points to.This is typically used when you do not want to endorse external links, or when the links are advertisements, user-generated content, etc., which helps prevent irrelevant links from affecting the SEO performance of your website and avoiding potential penalty risks.

2. Ask: I added a link in the background, but the front page did not display it. What could be the reason?Answer: This may be caused by several reasons. First, please check if your template file uses the tags correctly.{% linkList friendLinks %}and their internal structuresforIs the loop structure complete?Secondly, confirm if you have cleared the AnQiCMS system cache (usually there is an option to 'Update Cache' in the background), because template changes and data updates may require cache refresh to take effect.Finally, check if the friendship link you added is set to the display status (if this option is available in the backend).

3. Question: Can I display different friend link lists for different pages or categories of the website?Answer: AnQiCMS'slinkListThe label is currently used to retrieve the global list of friendship links; it does not provide parameters to filter by category ID or other page attributes directly. If you need to implement this requirement, you can consider categorizing the links in the "friendship link management" backend and filtering them through the template.ifSentence combinationitem.RemarkField or custom logic to manually filter and display.Alternatively, if you are very familiar with template development, you can also consider creating multiple 'friend link lists' through content models or single-page features, and then calling different content based on the page ID or category ID.