How to retrieve and display the list of Banner carousel images configured on the website homepage?

Calendar 👁️ 85

In Anqi CMS, the Banner carousel on the homepage is an important element to attract visitors' attention and display key content.Correctly obtain and display these banner images, which can greatly enhance the visual effects and user experience of the website.AnQi CMS provides intuitive functions and flexible template tags, allowing us to easily achieve this goal.

Step 1: Configure your Banner slideshow in the background

Before starting to display Banner on the website front-end, we first need to configure it in the Anqi CMS backend management system.Generally, you can find the configuration entry in the "Page Resources" or similar "Banner Management" area.

Here, you can create a new Banner entry, upload an image (i.e., Logo) for each Banner, set the link (Link) to redirect after clicking, add image alternative text (Alt) for search engine understanding and accessibility, and write a brief description (Description).

A key setting is the 'group name' (type).The Anqi CMS allows you to set different groups for different Banner sliders.For example, you can create a group named "Home Carousel" to display the Banner on the homepage.This way, when you call it in the template, you can accurately specify which group's Banner to display.Make sure to select a clear group name for the homepage carousel, such as "default" or "Homepage Banner", and maintain consistent image sizes to ensure the visual harmony of the carousel.

Second step: Call and display the Banner carousel in the template

After completing the background configuration, the next step is to display these exquisite banner images on your website homepage.This is mainly achieved through the template tags of AnQi CMS. Usually, these codes are placed in your website template files.index.htmlin the public fragment files it contains.

AnQi CMS provides a specialbannerListLabel, it can help us get the background configuration Banner list.

Basic calling method

To get the list of Banners for all default groups, you can use the following code snippet:

{% bannerList banners %}
    <div class="homepage-banner-carousel">
        {% for item in banners %}
        <a href="{{item.Link}}" target="_blank">
            <img src="{{item.Logo}}" alt="{{item.Alt}}" />
            <h5>{{item.Description}}</h5>
        </a>
        {% endfor %}
    </div>
{% endbannerList %}

In the code above:

  • {% bannerList banners %}The tag will assign the Banner list data configured on the backend to a variable namedbanners.
  • {% for item in banners %}The loop will iterate overbannersEach item in the list of banners.
  • Inside the loop,itemThe variable represents the data of the current single banner being processed. We can access it byitem.LogoGet the image address,item.LinkGet the jump link,item.AltGet image alternative text anditem.DescriptionGet the description text of the Banner.

Call the Banner of the specified group

If you have set a specific group name for the home page Banner in the background, such as "Home Slide", then when calling it in the template, you need to specify the group throughtypethe parameter:

{% bannerList banners with type="首页幻灯" %}
    <div class="homepage-banner-carousel">
        {% for item in banners %}
        <a href="{{item.Link}}" target="_blank">
            <img src="{{item.Logo}}" alt="{{item.Alt}}" />
            <h5>{{item.Description}}</h5>
        </a>
        {% endfor %}
    </div>
{% endbannerList %}

Bywith type="分组名"Parameters, you can ensure that only Banners belonging to a specific group are displayed, which is very useful when managing multiple carousel areas.

Add special styles to the first Banner.

In many carousels, the first Banner item may need to be active as soon as it loads, or have special styles. You canforloop.CounterTo determine if the current element is the first element of the loop:

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

Here, we use{% if forloop.Counter == 1 %}To determine if the current loop is the first one, if so, then addactiveClass name to配合前端JavaScript or CSS to implement default activation effect.

Practical suggestions and precautions

  • Image optimization:The uploaded Banner image should be appropriately compressed, maintaining a moderate file size to ensure the website loads quickly.At the same time, unify the size and aspect ratio of the images can make the carousel look more professional and beautiful.

Related articles

How to retrieve and loop the list of friend links in the AnQiCMS template?

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友情链接 function 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 thoroughly introduce how to obtain and loop through the list of friendship links on AnQiCMS templates, helping you easily realize the interconnection of websites.

2025-11-08

How to get the complete content, SEO information, and associated images of a single page?

In daily website operations, independent pages such as "About Us", "Contact Information", etc., play an important role in conveying core information and shaping the brand image.As content operators, we often need to gain a deep understanding of the structure of these pages, including their main content, SEO information, and all associated image resources, in order to carry out fine management, optimization iteration, or flexible page layout.AnQiCMS provides an intuitive and powerful template tag system, making it easy to obtain these page data.

2025-11-08

How to get and loop through all independent pages in AnQiCMS template (such as About Us)?

In AnQi CMS, sometimes we need to list some independent pages in the website's navigation bar, footer, or other specific areas, such as "About Us", "Contact Us", "Privacy Policy", and so on.These pages usually contain fixed content and do not belong to a specific category or article model. AnQiCMS refers to them as 'single pages'.Fortunately, AnQiCMS provides a very intuitive and powerful template tag that can easily retrieve and loop through information for these single pages.### Core Tag

2025-11-08

How to display the main category in the navigation bar and show the latest products under this category in the dropdown menu?

In website operation, a clear and effective navigation system is the key to improving user experience and website professionalism.AnQiCMS (AnQiCMS) with its flexible content management and powerful template engine, can help us easily achieve complex navigation requirements.Today, let's discuss how to display the main categories in the website's navigation bar and also show the latest products under the category in a dropdown menu when the mouse hovers over it.### One, Understand the navigation and content management basics of AnQiCMS One of the core advantages of AnQiCMS lies in its modular content management system

2025-11-08

How to display a list of articles with pagination and customize the style and number of pagination navigation pages?

Today, with the increasing richness of website content, how to efficiently display a large number of articles while ensuring a smooth browsing experience is a problem that every website operator needs to consider.AnQiCMS (AnQiCMS) provides a powerful and flexible article list pagination feature, which not only helps to optimize the content presentation of the website, but also allows for better integration into the overall website design through custom styles and page number settings, enhancing the user interaction experience.Next, we will delve into how to implement pagination of the article list in Anqi CMS

2025-11-08

How to dynamically add a website name suffix or custom delimiter in the page title (Title)?

The page title (Title) is the 'front door' of a website on the search engine results page. It not only can intuitively tell users the content of the page, but it is also an important indicator for search engines to evaluate the relevance and authority of the page.An optimized page title that can significantly improve click-through rates and the website's search engine ranking.In AnQiCMS, you can flexibly control the way page titles are generated, especially by dynamically adding the website name suffix and custom delimiters to achieve a unified brand image and better SEO effect.### AnQiCMS in TDK

2025-11-08

How to implement search through URL parameters (such as `q=keyword`) on the article list page and display the results?

It is crucial to provide users with a convenient and accurate content search experience in website content operation.When the number of articles on the website continues to grow, a practical search function can greatly enhance user satisfaction and the efficiency of content access.AnqiCMS as an efficient content management system provides a flexible way to implement the URL parameter search function for the article list page, allowing visitors to directly search and view related content by adding parameters such as `q=keywords` to the URL.

2025-11-08

How to combine custom parameters (such as "area", "house type") for multi-condition filtering on the article list page?

In AnQi CMS, to implement multi-condition filtering on the article list page, such as filtering based on custom parameters such as "area" and "house type", it requires us to cleverly combine the system-provided "content model" feature with the "document parameter filtering tag" ("archiveFilters") and "document list tag" ("archiveList") of the front-end template.The entire process can be divided into several core steps, let's take a detailed look together.### Core Function: Customize Content Model and Parameters Basic Implementation of Multi-Condition Filtering

2025-11-08