AnQiCMS provides excellent flexibility in website content management, especially when dealing with category page displays. It is not limited to a single fixed layout but allows users to set personalized display templates for category pages based on different business needs and design concepts.This is undoubtedly a very practical feature for operators who hope to enhance user experience, strengthen brand image, or optimize specific SEO strategies through differentiated content display.
How is it implemented to customize the display template of the category page in AnQiCMS?This is mainly due to the flexible template mechanism of the system, which provides two main ways to meet your customization needs.
Overview of AnQiCMS template mechanism
AnQiCMS's template system is based on syntax similar to Django template engine, using.htmlAs a template file suffix, and place all template files in/templateDirectory.You can create your own template theme folder under this directory and organize your template files.This design makes template creation very intuitive and easy to manage.
When customizing the category page template, AnQiCMS provides two paths: one is to automatically match using the system's predefined naming conventions, and the other is to manually specify the template for a specific category through the backend settings.
Method one: Use AnQiCMS's conventional naming to automatically match
AnQiCMS provides an intelligent template matching mechanism.When you have not explicitly specified a template for a category, the system will automatically search for and load the corresponding template file according to a set of predefined rules.This is particularly applicable to scenarios with a large number of categories, and where the display structure of these categories is mostly similar.
The most common classification list page template, AnQiCMS will try to find the following two files in your template theme folder:
- General model list template:For example, if you have an 'article' content model, the system will look for a file named
{模型table}/list.htmlsuch asarticle/list.htmlorproduct/list.html)。If this file exists and no more specific template is specified, all category list pages belonging to this model will use it. - Specific category ID template:If you want to design a unique layout for a specific category (such as a category with ID 12) without manually setting it in the background, you can create a layout named
{模型table}/list-{分类id}.htmlsuch asarticle/list-12.html)。When the user accesses the list page of the article category with ID 12, the system will load this more specific template first.
This convention-based naming allows you to achieve unified or local micro-adjustment design with a lower maintenance cost when managing a large number of categories.
Method two: flexibly specify the template through backend settings.
If some of your categories require a completely unique display style, even the default conventions cannot satisfy, AnQiCMS also provides a powerful feature to directly specify templates in the background.This provides great convenience for operators who need highly customized pages (such as specific product display pages, special event pages, or corporate solutions pages).
To specify the category template through the backend, you can follow the following steps:
Create a custom template fileFirstly, in your AnQiCMS template theme folder (for example,
/template/您的主题名/Within the bracket, create a new HTML template file. You can place it in any subdirectory, likecustom/special_category.html. Make sure the content of this template file meets your design requirements.Login to the background and edit categories: Then, log in to the AnQiCMS background management interface, navigate to the left menu under 'Content Management', and click the 'Document Category' option.
Specify category templateIn the document classification list, find the category you want to customize the template, and click the "Edit" button on the right.Enter the category editing page and scroll down to find the "Other Parameters" section.Here, you will see a text box named "Category Template".
Enter template pathIn the "Category Template" input box, enter the path and filename of the custom template file you just created relative to your theme root directory. For example, if the file you created is
custom/special_category.htmlthen entercustom/special_category.html.Apply to subcategory (optional)In the "Category TemplateBy default, the category template will not automatically inherit to the lower-level categories.If you want all the subcategories under the current category to use the custom template you set, you can check this option.
After completing the settings and saving, when the user visits this specific category page, AnQiCMS will load the custom template you specified in the backend to display the content.
Ensure that the template file path you have entered is accurate and correct, as if the system cannot find the corresponding template file, it may cause this category page to fail to open normally.
Custom category template tips
In your custom category template, you can fully utilize the various template tags provided by AnQiCMS to retrieve and display data. For example:
- Use
{% categoryDetail ... %}Translate the content of 'auto' to 'English', and keep the original format of the JSON array. - Use
{% archiveList ... %}Label to get the document list under the category, and can be sorted, filtered, and paginated according to needs. - Don't forget the SEO optimization of the page, through
{% tdk ... %}Label to ensure the correct setting of page title, keywords, and description. - If your website supports mobile devices, don't forget to
mobile/Create the corresponding mobile template under the directory to provide **of cross-device browsing experience. - During template development, frequent previews are good habits, which can help you discover and correct issues in a timely manner, ensuring the final effect meets your expectations.
Through combining conventional naming and flexible backend specification, AnQiCMS makes the template customization of category pages both efficient and powerful.You can choose the most suitable strategy according to your specific needs to create a website page that is both beautiful and practical.
Common Questions (FAQ)
1. If the custom category template file I specified does not exist, how will the category page display?
If AnQiCMS cannot find the custom category template file you have set in the specified path, the category page will not load normally and display an error message.In order to avoid this situation, please make sure to confirm that the corresponding template file has been uploaded to the correct path after specifying the template name in the background.
2. How to get the name and description of the current category in a custom category template?
In a custom category template, you can use{% categoryDetail with name="Title" %}to get the category name,{% categoryDetail with name="Description" %}Get the category description and other informationcategoryDetailThe fields supported to get detailed information of the current category. These tags will automatically identify the category of the current page and no additional ID needs to be specified.
3. Can I set different display templates for PC and mobile on the same category?
Of course, you can. AnQiCMS supports multi-terminal templates. You just need to create a subdirectory namedmobile/in your template theme folder. Then, in the `mobile/