How to display the language switch options and hreflang tags on a multilingual site in AnQiCMS?

Calendar 👁️ 65

Building multilingual websites in AnQiCMS and providing convenient language switching options as well as correct hreflang tags is a key step in expanding the international market and improving user experience.AnQiCMS with its flexible architecture provides a clear path to achieve this goal, allowing your website content to accurately reach global users while ensuring search engine friendliness.

AnQiCMS Multi-language Implementation Overview

AnQiCMS is designed to integrate multi-language support with multi-site management features deeply.This means that each different language version is usually treated as an independent site for management within the system.The benefit of this design is that the backend management, content publishing, URL structure, and even template styles of different language sites can be highly independent and customizable, thereby avoiding the complexity that may be brought by multiple languages on a single site.

For example, your Chinese site (www.example.com) and English site (en.example.com) Will have their own independent content libraries, and can publish completely different articles, products, or pages.The 'Default Language Package' setting of AnQiCMS mainly affects the language of the background management interface or the system built-in prompt information, while the core content displayed on the website front end, such as article titles, text, category names, etc., needs to be created and maintained separately for each language site.

Based on such an architecture, AnQiCMS provides powerful tag functions to help us easily implement language switching and hreflang tag integration on the front end.

Step 1: Configure multilingual site

Firstly, you need to set up multiple independent language sites in the AnQiCMS backend.

  1. Install the main site: If you have not installed AnQiCMS yet, please complete the installation of the main site first.
  2. Create a new language site:Log in to your AnQiCMS main site backend. In the left menu, find the 'Multi-site Management' feature, and click 'Add New Site'.
    • In the pop-up interface, you need to fill in the corresponding information for each language site. For example, to create an English site:
      • Site Name:For example, "English site".
      • Site root directory:This is an independent directory path used to store the cache, configuration files, and other data of the site, for example/app/en_example_comMake sure this directory name is unique.
      • Website address:Set the domain name or subdomain name to be used by the language site, for examplehttps://en.example.comorhttps://www.example.com/en.
      • Admin account password:Set up an independent backend administrator account and password for this new site.
      • Database name:Create an independent database for this site, such asen_example_com_dbIf you are using AnQiCMS in Docker environment and reusing the default database account information, you usually do not need to fill in the database account password.
      • Select the template to use:You can choose a separate template for each language site, or you can reuse the existing template and make language-related modifications.

After completing the site addition, you will also need to configure the corresponding reverse proxy at the server level (such as Nginx or Apache), route the user's requests correctly to the AnQiCMS Docker container port (default is 8001), and ensure that your domain name resolution is correct.This operation is similar to the AnQiCMS installation and deployment document regarding multi-site configuration, ensuring that each language site can access independently.

Step two: Add language switch options in the template.

After your multilingual site is configured and can be accessed independently, the next step is to provide a prominent language switch option on the website front end, making it convenient for users to choose their preferred language. AnQiCMS provides a namedlanguagesThe powerful tag, which can get information about all configured language sites.

Usually, we recommend placing this code in the global template file, for example.template/{您的模板名称}/bash.htmlorheader.htmlIt ensures that it is visible on all pages.

You can use it in the following way:languagesLabel to display language switch options:

{%- languages websites %}
{%- if websites %}
<div class="language-switcher">
    <span>切换语言:</span>
    {%- for item in websites %}
    <a href="{{item.Link}}" {% if item.Link == currentUrl %}class="active"{% endif %}>
        {%- if item.LanguageIcon %}
        <img src="{{item.LanguageIcon}}" alt="{{item.LanguageName}}图标" />
        {%- else %}
        {{item.LanguageEmoji}}
        {% endif %}
        {{item.LanguageName}}
    </a>
    {%- endfor %}
</div>
{%- endif %}
{%- endlanguages %}

In this code block:

  • {% languages websites %}It will traverse all multilingual sites configured in the AnQiCMS backend and store their data inwebsitesthe variable.
  • item.LinkIt will provide the complete URL of the language site.
  • item.LanguageNameDisplay the name of the language (e.g., "Chinese", "English").
  • item.LanguageEmojiProvide the language corresponding Emoji icon, if your template supports displaying Emoji, this is a concise choice.
  • item.LanguageIconIf you have configured icons for language in the background, the icon URL will be displayed here. You can choose to display Emoji or icons according to your actual needs.
  • {% if item.Link == currentUrl %}class="active"{% endif %}This line (currentUrlThe URL needs to be passed into the template as a global variable or obtained in some other way and can be used to highlight the language that the current user is visiting.

Step 3: Implement hreflang tags

In addition to providing users with visible language switching options, it is important to configurehreflangtags are crucial for the SEO of multilingual sites.hreflangThe tag tells search engines about other language versions of a specific page, which helps avoid duplicate content issues and ensures that users see the correct language and regional content in search results.

hreflangLabels need to be placed on each page.<head>You can continue to use it.languagestags to dynamically generate these links:

{%- languages websites %}
{%- for item in websites %}
<link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">
{%- endfor %}
{%- endlanguages %}

In this code block:

  • item.LinkIt also provides the URL of each language site.
  • item.LanguageIt provides the ISO 639-1 language code for the language site (for examplezh-cn/en-us)。These codes are automatically generated by AnQiCMS when creating a language site, or when you configure it in the background.

Add this code to the relevant part of your template.<head>For example, part (such astemplate/{您的模板名称}/bash.htmlorhead.html), to ensure that each page includes the correcthreflanginformation.

Integration with **practice

  • Location of the template file: languagescode of tags, whether it is a language switch option orhreflangTags should be placed in the global header template file of the website (such asbash.html/header.html) to ensure they are loaded and rendered correctly on all pages
  • Content synchronization:Since each language version is a separate site, you need to maintain the content separately for each site.When releasing new articles or products, remember to publish and translate them on all relevant language sites.
  • Unified URL structure:Plan a clear and consistent URL structure (for example, using subdirectories/en/or subdomainsen.example.com) helps users and search engines understand your multilingual content layout.
  • Standardized tags:ThoughhreflangSolved the multilingual content issue but still recommends using it on each page<link rel="canonical" href="..."/>The tag points to the main URL of the language version to avoid unnecessary crawler confusion. AnQiCMS providestdkLabel to get the specification link.

By following the above steps, you can effectively display multilingual in AnQiCMS.

Related articles

How to get and display detailed information of user groups in AnQiCMS template?

In AnQiCMS, user group management is one of the core functions for building differentiated services and content monetization systems.It is crucial to display detailed information about user groups accurately in the front-end template, whether it is to provide exclusive content for VIP users or to set access restrictions for users of different permission levels.This not only improves the user experience, but also effectively guides users to understand and upgrade their own permissions.How can we flexibly obtain and display the detailed information of these user groups in the AnQiCMS template?

2025-11-07

How to parse and output HTML code in AnQiCMS template instead of escaping it?

When using AnQi CMS for website content creation and template design, we often encounter a problem related to HTML code display: Why is the HTML code I enter in the background editor displayed as plain text on the front page instead of being parsed by the browser as actual HTML elements?This is actually the content management system that defaults to enabling HTML content escaping for website security.This article will delve into how to effectively control the output of HTML code in the AnQiCMS template, ensuring that it is parsed correctly and not displayed as escaped.

2025-11-07

How to get the thumbnail of AnQiCMS image resources and display it?

AnQiCMS focuses on visual effects and page loading efficiency in content display, therefore, how to efficiently obtain and display thumbnail images of image resources is a common problem we encounter in daily operations.It is fortunate that AnQiCMS provides a very convenient and flexible way to handle image thumbnails, allowing us to easily meet various display needs. --- ### How to manage and generate image thumbnails in AnQiCMS?

2025-11-07

How to format floating-point numbers and retain a certain number of decimal places in AnQiCMS templates?

In website content operation, we often need to display floating-point numbers such as prices, percentages, ratings, and so on.The precision and display method of these numbers directly affect the user experience and the professionalism of information.AnQi CMS knows this need and provides a powerful and flexible floating-point number formatting function in the template engine, allowing you to easily control the display accuracy of floating-point numbers.Next, we will explore two main methods of formatting floating-point numbers and retaining specified decimal places in AnQiCMS templates: the `floatformat` filter and the `stringformat` filter

2025-11-07

How to manage website navigation links and display them on the front page in AnQiCMS?

When building and managing a website, a clear and intuitive navigation system is the foundation of user experience and search engine optimization.AnQiCMS provides a flexible and powerful navigation management mechanism, allowing you to easily organize the website structure and elegantly present it to users. ### One, Back-end Navigation Management: Build the Skeleton of Your Website The navigation management feature of AnQiCMS is located in the "Back-end Settings" menu. Click on "Navigation Settings" to enter.Here, you can build a clear navigation system for the website like stacking blocks.

2025-11-07

How to set contact information in AnQiCMS and display it on the front page (such as phone number, address, WeChat)?

In today's digital age, a website's contact information is not only for displaying information but also a bridge for communication between the enterprise and the customer.Clear and easily accessible contact information can effectively enhance customer trust and promote business conversion.AnQiCMS (AnQi Content Management System) knows this well and provides a simple and efficient way to set up and display various contact methods, whether it's phone, address, or WeChat. Let's take a step-by-step look at how to configure and display this key information in AnQiCMS.### First step: Set your contact information in the background First

2025-11-07

How to loop and display the titles (ContentTitles) of AnQi CMS documentation in the front-end template?

Dynamically display document content title: The Loop and Application of ContentTitles in AnQiCMS front-end template When operating website content with AnQiCMS, we often need to provide users with a better reading experience and navigation convenience. One very practical feature is to automatically generate the article table of contents (Table of Contents).AnQiCMS considers this very carefully, it can automatically extract the titles from the document content and provide them to the front-end template in the form of `ContentTitles`. Today

2025-11-07

How AnQiCMS supports custom content models to implement

During the process of building and operating a website, we often encounter such challenges: the standard article or product templates provided by the content management system (CMS) often cannot fully match the unique needs of our business.AnQiCMS (AnQiCMS) is aware of this pain point and therefore designed 'flexible content model' as one of its core highlights from the beginning, aiming to help users break free from the束缚 of traditional CMS and achieve personalized content management in the true sense.

2025-11-07