How to effectively call and display the friend link list in the template when building and managing a website using AnQiCMS is a common and practical need.Friendship links can not only help improve the SEO performance of the website, but also provide users with more valuable external resources.The powerful template engine of AnQiCMS combined with its backend features makes this operation very direct.

Manage friend links: Start from the backend

Before displaying the link on the website front-end, we first need to set it up in the AnQiCMS backend.AnQiCMS provides a user-friendly friend 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 add new links.

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

  • Link NameThis is the name displayed on the website front-end for the friendship link, it should be concise and clear, expressing the content of the link clearly.
  • Link AddressThis is the complete URL pointed to by the friendship link, be sure to ensure its accuracy.
  • NoteYou can fill in some internal descriptions for convenience in management, which are usually not displayed on the front end.
  • Nofollow attributeThis is a very important option. Checking 'nofollow' tells the search engine not to follow the link and not to pass on your website's weight.This is very useful to avoid the impact of unrelated links on the SEO of your website, or when you do not fully trust the content to which the link points.

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

Call the friend link in the AnQiCMS template

After configuring the friend links on the background, the next step is to display them in the template on the website front end.The AnQiCMS template system adopts syntax similar to the Django template engine and provides special tags for convenient data retrieval.

To display the friend link list, we need to uselinkListthe tag. This tag is specifically designed to retrieve the friend link data configured on the backend.

Its basic usage is:

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

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

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

Let's look at a specific example of how to organize code in a template to display友情链接

{% 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 obtain friendship link data and assign it tofriendLinksVariable.
  • {% if friendLinks %}This is a very practical judgment, it checksfriendLinksThe list is empty. The internal HTML structure will only be rendered when the backend actually adds friendship links, 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 the style requirements of your website.
  • {% for item in friendLinks %}ThisforThe loop will iterate overfriendLinksEach link in the list. In each loop, the data of the current link will be assigned toitemVariable.
  • <li>...</li>: List item, used to carry the information of a single link.
  • {{item.Link}}: Display the current friend link URL address.
  • {% if item.Nofollow == 1 %} rel="nofollow"{% endif %}: This is a conditional judgment, if the background is set to 'nofollow' for the link, it will be automatically added here.rel="nofollow"Property. This is an important detail for SEO optimization.
  • target="_blank"This attribute is usually added to friend links to open the link in a new tab, improving user experience and preventing visitors from leaving your website.
  • {{item.Title}}This displays the name of the current friend link.
  • {% if item.Remark %}<span class="link-remark">{{item.Remark}}</span>{% endif %}If the backend has filled in a note for this link, it will be displayed here.

By using such a code structure, you can flexibly call and display the friend link list in the AnQiCMS template.Generally, friend links are placed at the footer of a website or on an independent "friend links" page.

Tips and **Practice

  1. Template File Location Usually, the code snippet for a friend link can be placed in partial/footer.htmlsuch a public file and then accessed by {% include "partial/footer.html" %}The way to reference in other templates, maintain 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 friend links so that it matches the overall style of your website.
  3. Multi-site callIf you have used the AnQiCMS multi-site management function and want to call the friendship link of a specific site, you canlinkListthe tag withsiteIdparameters, for example{% linkList friendLinks with siteId="2" %}To specify the friendship links of the site with ID 2. However, for most single-site users, this parameter does not need to be specified.

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


Frequently Asked Questions (FAQ)

1. Ask: What is the use of the friend link's attribute?rel="nofollow"What is the use of the attribute?Answer:rel="nofollow"The attribute tells the search engine not to pass the "weight" or "trustworthiness" of your website to the page linked by this link.This is typically used when you do not want to endorse external links, or when 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: Why doesn't the friend link I added in the background show up on the front page? What could be the reason?Answer: This could be due to several reasons. First, please check if your template file is using{% linkList friendLinks %}tags correctly, and the internalforIs the loop structure complete? Secondly, confirm whether you have cleared the AnQiCMS system cache (usually there is an 'update cache' option in the background), as template changes and data updates may require cache refresh to take effect.Finally, check if the friendship link you added is set to display status (if there is this option in the backend).

3. Ask: Can I display different friend link lists for different pages or categories on the website?Answer: AnQiCMS'linkListThe tag is mainly used to obtain the global friend link list, it does not provide filtering parameters by category ID or other page attributes directly. If you need to implement this requirement, you can consider classifying the links in the background "Friend Link Management" and filtering them in the template throughifstatements to combineitem.RemarkField or custom logic to manually filter and display. Or, if you are very familiar with template development, you can also consider creating multiple "friend link lists" through content models or single-page functions, and then calling different content based on page ID or category ID.