How to customize the display content and link of the homepage Banner in AnQiCMS template?

Calendar 👁️ 68

In website operation, the homepage banner acts as the 'face' of the website, and its visual effects and guiding role are crucial.A well-designed, tasteful Banner can not only attract visitors' attention but also effectively convey the core information of the website and guide users to take the next step.For friends using AnQiCMS, how to flexibly customize the display content and links of the home page Banner is a key step to improve the user experience and marketing effect of the website.

AnQiCMS provides great flexibility in template design, allowing us to easily control the display of the home page banner.This is mainly due to its powerful template tag system. Next, we will discuss how to customize the display content and link of the home page Banner in AnQiCMS template.

Understand the Banner management mechanism in AnQiCMS

In AnQiCMS, the management of the home page banner is usually carried out in a specific module on the backend.Here, we can upload Banner images, set the title, description, link address, and alternative text (Alt), which together constitute the data required for Banner display on the front end.

A very practical feature is that AnQiCMS allows for "grouping" of Banners.This means you can create multiple Banner collections, such as "Home Carousel", "Sidebar Ad Slots", and so on.Each group can include a set of independent Banner images and settings, greatly enhancing the flexibility of content operation.When configuring in the background, we need to pay attention to filling in clear titles, descriptions, and accurate links for each Banner entry, and selecting the group it belongs to.

Call the homepage Banner list in the template

In the template files of AnQiCMS, we can usebannerListThe tag is used to call the background configuration of the Banner list. This tag is very intuitive, it will return an array of Banner entries for us to loop and display in the template.

A basic call method is as follows:

{% bannerList banners %}
    {% for item in banners %}
        <!-- 这里是Banner的显示内容和链接 -->
    {% endfor %}
{% endbannerList %}

In this code block,bannersIt is a custom variable name that carries all the Banner data obtained from the backend. ThroughforLoop, we can visit each Banner entry one by one (here nameditem), and extract the various fields to construct the Banner display.

Custom Banner Display Content

Each Banner EntryitemContains multiple callable fields, which correspond to the content you fill in on the backend:

  • item.Logo: Banner image address.
  • item.TitleBanner title text.
  • item.DescriptionBanner description text.
  • item.Alt: Alternative text for banner image, important for SEO and accessibility.
  • item.Link: Banner click to jump link address.
  • item.Id: Banner's unique ID.

We can use these fields, combined with HTML and CSS to design the display style of the Banner. For example, a typical Banner structure may include images, titles, and descriptions:

{% bannerList banners %}
    {% for item in banners %}
        <a href="{{item.Link}}" target="_blank" title="{{item.Title}}">
            <img src="{{item.Logo}}" alt="{{item.Alt}}" />
            <div class="banner-content">
                <h2>{{item.Title}}</h2>
                <p>{{item.Description}}</p>
            </div>
        </a>
    {% endfor %}
{% endbannerList %}

In the code above,item.Linkwas used as<a>label'shrefThe property ensures that the Banner can be correctly redirected when clicked.item.Logoused for<img>label'ssrcwhileitem.AltThen it was filled.altProperty.item.Titleanditem.DescriptionIt is used to display text information.

Add and modify the Banner link.

The link of the banner is directly accesseditem.LinkField is obtained. In constructing<a>When labeling, we usually set it tohrefthe value of the attribute.

If you want the Banner link to open in a new window or new tab, you can in the<a>the tag withtarget="_blank"attribute. At the same time, to inform the search engine that the link does not pass weight, you can optionally addrel="nofollow"Properties, this is quite common in some advertising or external link scenarios.

Practical advanced skills

1. Call the Banner of the specified group

The feature of Banner grouping mentioned earlier is a very powerful function. If you want to call different Banner collections at different positions on the homepage, such as the main carousel at the top of the page and the activity promotion Banner in the middle of the page, you can make use oftypeSpecify the parameter to call the Banner group.

Suppose you have created a Banner group named "Slide" in the background, you can call it like this:

{% bannerList banners with type="幻灯" %}
    {% for item in banners %}
        <a href="{{item.Link}}" target="_blank">
            <img src="{{item.Logo}}" alt="{{item.Alt}}" />
            <h3>{{item.Title}}</h3>
        </a>
    {% endfor %}
{% endbannerList %}

By adjustingtypeThe value of the parameter, which can be flexibly displayed in the template to show different Banner content in different scenarios.

2. Apply special style processing to the first Banner.

In carousel and other scenarios, we may need to apply special styles such as 'active' to the first Banner entry.forin the loopforloop.CounterThe variable helps us determine which loop we are currently in:

{% bannerList banners %}
    {% for item in banners %}
        <div class="banner-item {% if forloop.Counter == 1 %}active{% endif %}">
            <a href="{{item.Link}}" target="_blank">
                <img src="{{item.Logo}}" alt="{{item.Alt}}" />
                <h4>{{item.Title}}</h4>
            </a>
        </div>
    {% endfor %}
{% endbannerList %}

3. Handling the case when there is no Banner

If a Banner group is not configured with any Banner or due to other reasonsbannersThe list is empty, we can use{% empty %}Label to provide alternative content, enhance user experience:

{% bannerList banners with type="幻灯" %}
    {% for item in banners %}
        <a href="{{item.Link}}" target="_blank">
            <img src="{{item.Logo}}" alt="{{item.Alt}}" />
        </a>
    {% empty %}
        <div class="no-banner-placeholder">
            <p>暂无Banner内容,敬请期待!</p>
            <img src="/static/images/default-banner.jpg" alt="默认Banner图" />
        </div>
    {% endfor %}
{% endbannerList %}

4. Use filters to optimize images

AnQiCMS also provides a variety of filters to process images, for example|thumbYou can get the thumbnail address of the processed image, which is very useful for responsive design and page loading speed optimization:

<img src="{{item.Logo|thumb}}" alt="{{item.Alt}}" />

This filter will return an image address after processing according to the thumbnail rules set in the background, to avoid loading large original images directly on the front-end.

By using these methods, we can fully utilize the flexibility of AnQiCMS templates, finely control the display content and links of the home page Banner, provide website visitors with a better browsing experience, and also provide strong support for the marketing goals of the website.


Frequently Asked Questions (FAQ)

Q1: I uploaded a Banner image on the backend, but it did not display on the front end. What could be the reason?A1: First, please check if your template file is using it correctly.bannerListTag to call Banner data. Next, confirm whether you have selected the correct group when uploading Banner on the backend(type), and when calling the template,bannerListlabel'stypeDoes the parameter match the group name set in the background. Finally, check if the Banner status is enabled, and if there is a cache, try to update the system cache.

Q2: How to set different styles for different Banners, such as some full-screen Banners and some small-sized Banners?A2: AnQiCMS'bannerListThe tag calls the Banner data, and the specific style is controlled by front-end HTML and CSS. You can set each Banner entry (item)Set a custom field (such as adding a text field named "Banner Style" in the backend), and dynamically add different CSS classes based on the value of this field in the template. Or, useforloop.CounterApply a special style to the Banner at a specific location. For Banners in different groups, since you have already passedtypeThe parameters are called differently and can be applied directly to the corresponding HTML structure with different CSS rules.

**

Related articles

How to implement the conversion of the first letter to uppercase or all uppercase of the string in AnQiCMS template?

In website content presentation, the case format of strings often needs to be flexibly adjusted according to different scenarios, such as the first letter of the article title in uppercase, the username in all lowercase, or the brand name in all uppercase.AnQiCMS as a feature-rich enterprise-level content management system, its template engine provides convenient and powerful filters (Filters), which help us easily implement the case conversion of these strings, making content display more standardized and professional.

2025-11-07

How to format a floating-point number to a specified number of decimal places in AnQiCMS template?

In the presentation of website content, we often need to display various numbers, such as product prices, discount percentages, or statistical data.These numbers are often floating-point numbers, and in order to ensure the beauty of the page layout and the clarity of the information, we usually need to format them, such as uniformly retaining two decimal places.In the AnQiCMS template, thanks to its flexible template engine, we can conveniently use the built-in `floatformat` filter to meet this requirement.

2025-11-07

How to automatically convert a URL string into a clickable hyperlink and set `nofollow` in the template of AnQiCMS?

In the daily operation of AnQi CMS, we often need to display external links in the website content.These links, if they are just simple text, not only affect the user experience, but also cannot effectively convey information.At the same time, in order to follow the **practice** of search engine optimization (SEO), especially for links pointing to external sites, we usually want to add the `rel="nofollow"` attribute to avoid unnecessary "weight loss" or passing unnecessary trust.AnQi CMS provides a simple and efficient method to solve this problem.### Core Function Revelation

2025-11-07

How to calculate the number of elements in a string (such as an article title) or an array (such as a tag list) in AnQiCMS templates?

In AnQi CMS template design, we often need to make accurate statistics of the content on the page, whether it is to dynamically display the number of data or to make conditional judgments based on the number, mastering how to calculate the number of elements in a string or array is particularly important.AnQiCMS's powerful template engine provides a concise and efficient method to handle these requirements.

2025-11-07

How to loop to display user group information in AnQiCMS template?

In the website built with AnQiCMS, the user grouping function provides us with powerful content management and user permission division capabilities, whether it is to implement membership content, display different information according to user level, or plan VIP services, user grouping is an indispensable foundation.How to flexibly display these user grouping information on the front-end template of a website, which is a focus for many operators.AnQiCMS uses a template engine syntax similar to Django, which makes template writing intuitive and efficient.When it comes to user group information, the system provides

2025-11-07

How to get and display detailed information of a specific user, such as username, avatar, and level in AnQiCMS template?

In website operation, displaying personalized information to users, such as usernames, avatars, and membership levels, can greatly enhance user experience and website interaction.AnQiCMS as a flexible content management system provides intuitive template tags to help us easily achieve this goal.The AnQiCMS template system has adopted a syntax similar to Django templates, allowing backend data to be called through concise tags.When we want to display detailed information about a specific user

2025-11-07

How to display or hide content blocks in AnQiCMS templates based on conditions (such as `if` statements)?

In website content operation, we often need to display or hide specific content based on different situations, such as displaying special event information on holidays or showing different operation buttons based on the user's status.AnQiCMS provides a flexible template engine, allowing you to easily implement these dynamic content controls, with the most core tool being the conditional statement - `if`. AnQiCMS template syntax is similar to the popular Django template engine, and it is very easy to get started with.

2025-11-07

How to iterate over an array or object list in AnQiCMS template and display loop count and remaining quantity?

In website content management, dynamically displaying list data is a basic and crucial function.Whether it is an article list, product display, or user comments, we need to present the data efficiently to the users.How to clearly mark the order of list items or inform the user how much content is left to browse can greatly enhance the user experience and readability of the content.AnQiCMS (AnQiCMS) with its flexible template engine, can help us easily meet these needs.

2025-11-07