How to implement the link display for multi-language site switching in AnQiCMS?

Calendar 👁️ 64

In today's globalized digital world, website multilingual support has become a key to reaching a wider audience and expanding market boundaries.AnQiCMS (AnQiCMS) fully understands this need, therefore it has made multilingual support one of its core features, aiming to help users efficiently build and manage multilingual websites.This article will focus on how to implement the switch link display of multi-language sites in AnQiCMS, and provide you with a comprehensive guide with necessary SEO practices.

Overview of the multilingual capabilities of AnQiCMS

AnQi CMS provides a flexible multilingual solution, which is not just simple text translation but also goes deep into the structure and content management of the website. Understanding its multilingual mechanism helps us better set up link switching:

  1. System language package and content language:AnQiCMS includes a variety of system language packages (such as Chinese, English), which mainly affect the background management interface and built-in prompt information of the website.However, the language of the actual website content (such as articles, product descriptions, category names, etc.) needs to be independently published and managed in the corresponding multilingual sites.This means, the Chinese site releases Chinese content, and the English site releases English content.

  2. Basic multi-site management:AnQiCMS with its powerful 'Multi-site Management' feature allows you to create and manage multiple independent website instances. Each instance can be configured for different language versions, for example, you can have aexample.comThe main site as a Chinese site, and then create oneen.example.comorexample.com/enThe child site as an English site. This architecture provides a solid foundation for independent management and display of multilingual content.

The key to implementing language switch links

The core of implementing language switch links for multilingual sites lies in utilizing the provided by AnQiCMSlanguagesLabel. This label can dynamically retrieve all the multilingual site information you configure in the background and display it on the front-end page for users to select and switch.

languagesThe label does not require any additional parameters, it will automatically retrieve and return a list of all multi-language sites that have been set.These sites are usually configured in the "Multi-site Management" or "Global Settings" in the background, each site is bound to a specific language identifier and access link.

UselanguagesLabel builds switch links

WhenlanguagesWhen the tag is called, it returns an array containing information about various language sites. You can useforLoop through this array to generate a clickable toggle link for each language site. Each language site is represented as anitemobject that contains the following useful fields:

  • item.LanguageNameThe display name of the language, such as "Chinese", "English".
  • item.LanguageThe language code, such as "zh-CN", "en-US", which is used for settinghreflangThe attribute is very critical.
  • item.LanguageEmoji: The Emoji expression corresponding to the language, such as 🌐, 🇺🇸, can be used for visualization display.
  • item.LanguageIconIf the language icon is uploaded on the backend, the URL of the icon will be provided here.
  • item.NameThe name of the site.
  • item.LinkThe complete URL of the language site, this is the target address where the user is redirected after clicking.
  • item.NofollowWhether the link should be added.rel="nofollow"Property.

Here is an example code snippet for displaying a language switch link in the header or footer area of a website:

{# 假设您已在后台配置了多个语言站点 #}
{%- languages websites %}
{%- if websites %} {# 确保存在至少一个语言站点配置 #}
<div class="language-switcher">
    <span>切换语言:</span>
    {%- for item in websites %}
    <a href="{{item.Link}}" title="切换到 {{item.LanguageName}}">
        {%- if item.LanguageIcon %} {# 如果有语言图标,优先显示图标 #}
        <img src="{{item.LanguageIcon}}" alt="{{item.LanguageName}} 语言图标" class="language-icon" />
        {%- elseif item.LanguageEmoji %} {# 否则显示Emoji #}
        <span class="language-emoji">{{item.LanguageEmoji}}</span>
        {%- endif %}
        <span class="language-name">{{item.LanguageName}}</span>
    </a>
    {%- endfor %}
</div>
{%- endif %}
{%- endlanguages %}

In this code, we first use{%- languages websites %}To get a list of all configured language sites and assign it towebsitesthe variable. Then, by{%- for item in websites %}Loop through each language site and dynamically generate<a>Tags. Each link'shrefProperties are used directlyitem.LinkMake sure that clicking will correctly jump to the corresponding language site. At the same time, according to your preference, you can choose to display language icons, Emojis, or language names, or their combinations.

Strengthening SEO: The Application of Hreflang Tags

In addition to the user-visible switch links, a very important aspect of search engine optimization (SEO) for multilingual sites is the correct use ofhreflang.hreflangThe tag can tell search engines that your website has multiple language versions or regional versions, thus helping search engines provide users with the most appropriate language or regional content.

hreflangLabels are usually placed in the HTML document's<head>area. Combinedlanguageslabel, you can easily generate corresponding links for each language versionhreflang:

{# 将这段代码放置在您的模板文件(如base.html或header.html)的<head>标签内 #}
{%- languages websites %}
{%- for item in websites %}
<link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">
{%- endfor %}
{%- endlanguages %}
{# 还需要一个默认的x-default,指向一个没有特定目标区域用户的通用版本,通常是主语言版本 #}
<link rel="alternate" href="{% system with name='BaseUrl' %}" hreflang="x-default">

This code will generate a label for each language site<link rel="alternate" hreflang="xx" href="URL">label. Among them,hreflangProperties useditem.Language(language code),hrefThe property points to the language site ofitem.Link. The last onex-defaultThe tag is recommended to add, it points to a generic version for users without a specific target region, usually the link to your main language site.

By following these steps, you not only provide users with an intuitive language switching method, but also provide search engines with clear multilingual site structure information, thereby enhancing the global visibility and user experience of your website.


Frequently Asked Questions (FAQ)

Q1: How does AnQiCMS distinguish between the language of the background interface and the language of the website content?A: AnQiCMS in the "Background Settings" section has an option called "Default Language Pack", which is mainly used to switch the interface language of the management background and some built-in hints on the website. Itwon'tAffect the language of the actual content you post on websites, such as articles and product descriptions.The language of the website content is managed according to each independent language site you create.For example, the content published on your English site is in English, and the content published on your Chinese site is in Chinese. They are independent content management systems.

Q2: Can I enable multi-language switching under the same domain (e.g., example.com/en, example.com/zh)?A: Yes, AnQiCMS supports this configuration method. You can create multiple sites through the "Multi-site Management" feature in the backend, and set their "site addresses" to different subdirectories under the same domain (such asexample.com/enandexample.com/zhThen, combine the server's pseudo-static rules (such as Nginx or Apache configuration) to correctly route access. That way,languagesTag generation:item.LinkThese subdirectory structures will be automatically reflected, enabling multilingual switching under the same domain.

Q3: If a language site does not have a translation version of a page, how will the switch link be displayed?A:languagesThe tag lists all multilingual site links that you have configured and enabled in the background, it is a site-level switch.It does not automatically judge whether a specific page (such as a specific article) has a corresponding translated version.

Related articles

How to define and use temporary variables in AnQiCMS templates to simplify content display?

When developing templates in AnQiCMS, we often encounter situations where we need to process some complex data or reuse a certain calculation result.To make the template code more concise, readable, and maintainable, AnQiCMS provides a powerful mechanism for defining and using temporary variables, mainly through the `with` and `set` tags.Reasonably utilizing them can greatly enhance our content display efficiency and flexibility. ### Simplified Content Display: Why do we need temporary variables?

2025-11-08

How to automatically parse a URL string into a clickable HTML link in AnQiCMS template?

In AnQiCMS template development, we often encounter the need: the URL string contained in the content should be automatically converted into a clickable HTML link to enhance user experience and page interactivity.Manually adding links is undoubtedly cumbersome and unrealistic, fortunately AnQiCMS provides powerful template filters that can help us easily achieve this function.AnQiCMS template engine supports Django-like syntax, which includes a series of practical filters that can process variable content.For automatic parsing of URL strings

2025-11-08

How to automatically wrap long text to a specified length in AnQiCMS template?

In the presentation of website content, the way long texts are displayed is often a key factor affecting user experience and the beauty of the page.When we need to display a long text content, such as an article summary, product description, or detailed introduction, in a more readable and layout-adaptive way, AnQiCMS's template function provides a powerful and flexible solution.AnQiCMS uses syntax similar to Django template engine, with various built-in filters (Filters) that can help us easily format text.

2025-11-08

How to safely output HTML code in the template without escaping in AnQiCMS?

When using AnQiCMS for website template development or content display, you may encounter situations where you need to output HTML code directly on the page, only to find that the code is automatically escaped, for example, the `<p>` tag becomes `&lt;This often confuses those who are new to it.In fact, this is the default measure taken by the AnQiCMS template engine for website security.### Understanding the default security mechanism of AnQiCMS templates The AnQiCMS template engine design has drawn inspiration from

2025-11-08

How to add `hreflang` tags in AnQiCMS template for multilingual pages to optimize SEO?

In today's globalized internet environment, many websites need to provide content for audiences of different languages or regions.To ensure that these multilingual pages can be correctly understood and displayed by search engines, the `hreflang` tag plays a crucial role.It can tell search engines that your website has multiple language versions and which version should be displayed to which user.

2025-11-08

How does AnQiCMS call and display data for specific sites based on different site IDs?

AnQiCMS multi-site data call: easily achieve content sharing and linkage display AnQiCMS is a content management system designed specifically for small and medium-sized enterprises and content operation teams, and its multi-site management function is one of its core highlights.In actual operation, we often encounter such needs: the main station needs to display the latest products of various sub-sites, or all sub-sites need to uniformly display the contact information of the company's headquarters, or multiple content platforms hope to aggregate and display articles on a specific theme.In this case, how to efficiently call and display data from a specific site is particularly important

2025-11-08

How to enable Markdown editor in AnQiCMS and display mathematical formulas and flowcharts correctly?

Today, with the increasingly rich content creation, plain text is no longer sufficient to express complex concepts.If complex mathematical formulas in academic articles or clear process diagrams in project management can be presented intuitively on the web, it will undoubtedly greatly enhance the professionalism and user experience of the content.AnQiCMS (AnQiCMS) understands this need, through the built-in Markdown editor and flexible frontend configuration, allowing you to easily implement these advanced content displays.This article will give a detailed introduction on how to enable Markdown editor in AnQiCMS

2025-11-08

How to correctly use the double curly braces `{{}}` and percentage signs `{% %}` tags in AnQiCMS templates to control the display logic of content?

When using AnQiCMS to build and manage websites, flexibly using template language is the key to improving efficiency and achieving personalized display.Among them, the double curly braces `{{}}` and the percentage tags `{% %}` are two core 'roles' that control the display logic of template files.They each have different responsibilities, understanding and using them correctly can help you easily master the powerful template functions of AnQiCMS.

2025-11-08