How to call the home page banner data of different sites under multi-site management?
AnQi CMS is an efficient and flexible content management system, and its multi-site management function is undoubtedly a powerful assistant for many enterprises and operators to improve efficiency and broaden their business horizons.How to cleverly call content between different sites in a multi-site architecture, especially for key visual elements like the home page banner, is a common problem in website operation.Today, let's delve into how to make use ofbannerListTags, accurately call data from the home page banners of different sites.
Flexible operation of multiple sites: The unique advantage of AnQiCMS.
The multi-site management function of AnQiCMS allows you to easily build and independently operate multiple websites, whether it is a group enterprise with different brand lines or an operation team targeting specific regions or service segments, everyone can benefit from it. Each site within AnQiCMS has independent configuration, content model, and data storage, but at the same time, the system also provides powerful cross-site data call capabilities, which is the core we are discussing today - throughsiteIdthis parameter.
In AnQiCMS, each new site created through the background "Multi-Site Management" feature will be assigned a unique numeric ID by the system, which is the key for cross-site data calls in our templates.It ensures that you can explicitly specify the data from site B in the template on site A, rather than the default data from the current site.
bannerListLabel: The tool called by the home page Banner
bannerListThe tag is used specifically in the AnQiCMS template system to obtain the home page banner data.Its basic usage is very intuitive, usually used on the homepage of a website or on a page that needs to display a Banner to cycle through preset carousels.
{% bannerList banners %}
{% for item in banners %}
<a href="{{item.Link}}" target="_blank">
<img src="{{item.Logo}}" alt="{{item.Alt}}" />
<h5>{{item.Title}}</h5>
</a>
{% endfor %}
{% endbannerList %}
In the above code,bannersIt is the variable name you define for Banner data, and you can access each Banner in the loop.Id/Logo(Image address),Link(link address),Description(Introduction) andAltImage Alt text and other properties.
bannerListLabels also support atypeParameters used to call the backend to create different Banner groups. For example, if you set a "Home Banner" group in the backend, you can also set a "Event Banner" group bytype="活动Banner"to call.
{% bannerList activityBanners with type="活动Banner" %}
{# 循环输出活动Banner数据 #}
{% endbannerList %}
Crossing the site fence:siteIdpower
Now, let's look at how to use it in a multi-site environment, by utilizingbannerListTags to call banner data from different sites. The answer lies in its support forsiteIdParameter.
siteIdThe parameter allows you to explicitly specify which site to retrieve Banner data from. When you do not providesiteIdthen,bannerListThe tag will default to retrieving the Banner from the current site. Once you specifysiteIdThe tag will look up the site data corresponding to the ID.
For example, assume you have a main site (Site A,siteIdwith ID 1) and two child sites (Site B,siteIdfor 2; Site C,siteIdFor 3). Do you want to display the Banners of the main site and the sub-sites B and C on the homepage template of the main site.
The following is an example of the code that achieves this goal in the main site template:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>主站点首页 - 多站点Banner调用演示</title>
{# 引入CSS和JS #}
</head>
<body>
<header>
<h1>主站点</h1>
</header>
<main>
<h2>主站点自己的首页Banner</h2>
<div class="banner-section main-site-banners">
{% bannerList mainSiteBanners %}
{% for item in mainSiteBanners %}
<div class="banner-item">
<a href="{{item.Link}}" target="_blank">
<img src="{{item.Logo}}" alt="{{item.Alt}}" />
<p>{{item.Description}}</p>
</a>
</div>
{% empty %}
<p>主站点暂无Banner数据。</p>
{% endfor %}
{% endbannerList %}
</div>
<h2>子站点B (siteId: 2) 的首页Banner</h2>
<div class="banner-section sub-site-b-banners">
{% bannerList siteBBanners with siteId="2" %} {# 指定siteId为2,调用子站点B的Banner #}
{% for item in siteBBanners %}
<div class="banner-item">
<a href="{{item.Link}}" target="_blank">
<img src="{{item.Logo}}" alt="{{item.Alt}}" />
<p>{{item.Description}}</p>
</a>
</div>
{% empty %}
<p>子站点B暂无Banner数据。</p>
{% endfor %}
{% endbannerList %}
</div>
<h2>子站点C (siteId: 3) 的“促销活动”Banner分组</h2>
<div class="banner-section sub-site-c-promos">
{% bannerList siteCPromotionBanners with siteId="3" type="促销活动" %} {# 指定siteId为3,并指定type为“促销活动” #}
{% for item in siteCPromotionBanners %}
<div class="banner-item">
<a href="{{item.Link}}" target="_blank">
<img src="{{item.Logo}}" alt="{{item.Alt}}" />
<p>{{item.Description}}</p>
</a>
</div>
{% empty %}
<p>子站点C的“促销活动”Banner分组暂无数据。</p>
{% endfor %}
{% endbannerList %}
</div>
</main>
<footer>
<p>© 2023 AnQiCMS 多站点演示</p>
</footer>
</body>
</html>
In the above example, we clearly demonstrated how to achieve this by using inbannerListthe tag withsiteId="X"Parameters, to accurately obtain banner data from the site with ID X. At the same time, we can also combinetypeParameters are used to call a specific group of Banners, which provides great flexibility.
Cautionary notes and **practice
- Confirm
siteIdBefore making cross-site calls, be sure to find the target site you want to call data from the 'Multi-site Management' interface in the AnQiCMS background.siteId. This ID is usually displayed directly in the site list or by clicking on the site editor to view the URL parameters. - Existence of data:
bannerListThe tag will only call the target site inAlready existsThe Banner data. If the target site does not have a Banner or does not specify onetypeGroup Banner, the tag will return an empty array. Therefore, add it to the template.{% empty %}Branching to handle cases with no data is a good habit, which can avoid blank pages or display errors. - Performance consideration: Although AnQiCMS is developed based on Go language, it performs excellently, but cross-site data calls will inevitably involve additional database queries.When designing, you should weigh the frequency of calls and data volume to avoid unnecessary performance overhead.For static content or banners with infrequent updates, consider using a caching mechanism.
- Template versatilityIf you need a set of templates to be reused across multiple sites and each site displays its own Banner, then in
bannerListthe tag, there is no need to specifysiteIdLet it default to fetching the current site's Banner. Only use it when you really need to display Banners from other sitessiteId. - Permissions and Security: AnQiCMS has already handled the data access permission control at the bottom level. At the template level, as long as you can access the tag, you can get the data without additional permission configuration.
Summary
AnQiCMS'bannerListLabel combinationsiteIdParameter, provides a simple and powerful solution for content calls under multi-site management.Whether it is the main station gathering the essence of the sub-stations or the sub-stations referencing the content of the main station, this flexible calling method can meet your operational needs.Mastering this skill will allow you to operate multiple sites in AnQiCMS with ease, manage and display website content more efficiently.
Frequently Asked Questions (FAQ)
Q1: How do I know each site?siteIdare?
A1:You can view it on the 'Multi-site Management' interface in the AnQiCMS backend.usually in the site list, each row displays the basic information of the site, including its unique numeric ID.If the content is not displayed directly on the page, click to enter the editing page of the site, the URL in the browser address bar is usually also foundid=XSuch parameters, where X is the site.