AnQi CMS provides extremely high flexibility in content display, one very practical feature is to set independent display templates for different article categories.This means you can customize unique visual styles and layouts for different categories of content, thus better highlighting the content, improving user experience, and even satisfying specific SEO needs.

In order to achieve this goal, we need to start from several aspects such as preparing the template file, setting up the background, and designing the template content.

Understand the concept of category and article templates

In AnQi CMS, templates are usually divided into two main types, each playing a different role in content display:

  1. Category template (list page template):This template is responsible for rendering the list page of articles under a certain category.For example, your website may have a "News and Information" category and a "Product Release" category. You may want the news list to be concise and clear, while the product list needs to display more product images and brief parameters.The category template is designed to meet the needs of this differentiated list display.
  2. Document template (detail page template):This template is used to render the detailed content page of a single article or product.For example, a technical article may require code highlighting and table of contents navigation, while a product detail page may require a carousel, parameter table, and online consultation button.The document template allows each content detail to be presented in the most suitable way for its characteristics.

The settings of these templates can be made in the category management, and can be covered more finely for individual article detail pages.

Template file organization and naming conventions

Before starting the setup, make sure you have created and uploaded the custom template file. The template files of AnQi CMS are usually stored in the root directory of the website./templateIn the folder. Each set of templates should have its own independent directory, for exampledefault.

When customizing templates, Anqi CMS provides some default naming conventions. If you follow these conventions, the system will be able to automatically apply the template without any additional settings in the background. For example:

  • Document detail default custom template: {模型table}/{文档id}.html(For example)article/123.htmlPage for article with ID 123)
  • Document list default custom template: {模型table}/list-{分类id}.html(For example)article/list-10.htmlPage for article category list with ID 10)
  • Default custom template for single page: page/{单页面id}.html

However, when we want to set an "independent" template for a specific category, the most flexible way is to explicitly specify the template file name in the category settings. You can name the template file in a clear and understandable way, for example,article/news_list_template.htmlUsed for news category list, orarticle/product_detail_template.htmlUsed for product details.

Operation steps: Set an independent template for article classification

Now, let's take a step-by-step look at how to set up independent display templates for different article categories in the Anqi CMS backend.

  1. Prepare to customize the template file:Before performing background settings, please make sure to create your exclusive category template and/or document template files in your theme template directory (for example/template/您的主题名称/), such as the following:

    • article/news_list.html(Used to display the list of articles in the "News Center" category)
    • article/product_showcase.html(Used to display the list of products in the "Product Showcase" category)
    • article/tech_article_detail.html(Used to display the details of articles under the "Technical Articles" category)
  2. Enter the category management interface:Log in to the Anqi CMS backend management interface. In the left menu bar, find and click 'Content Management', then select 'Document Category'.

  3. Edit Target Category:In the document category list, find the article category you want to set up a separate template for (such as "News Center"). Click the "Edit" button on the right side of the category to enter the category editing page.

  4. Set category template and document template:In the category editing page, scroll down and you will see a collapsible area named "Other parameters".Expand this area, and you will find the 'Category Template' and 'Document Template' input boxes.

    • Category template:Enter the custom template filename you prepared for the category article list page, for example:article/news_list.html.
    • Document template:If you want all the article detail pages under this category to use the same dedicated template, you can enter the corresponding template file name here, for examplearticle/tech_article_detail.html.

    You will also notice an option for 'Apply to subcategories'.If you check this option, all subcategories (and their articles) under the current category will inherit the category template and document template you set here, without the need to set them individually.This is very convenient for classification with hierarchical structure.

  5. Save settings:After filling out, click the "OK" or "Save" button at the bottom of the page to save your changes.

  6. Preview and Test:After completing the settings, please immediately visit the front end of your website, go to the category page of the independent template you just set up (for example, "News Center"), and check the details page of any article under this category to see if the page has been displayed according to the template you specified.

Practical tags for template content creation

When designing your custom template, you can fully utilize the rich template tags provided by Anqicms to dynamically obtain and display content. For example:

  • {% categoryDetail ... %}: Get detailed information about the current or specified category, such as category name, description, Banner image, etc.
  • {% archiveList ... %}: Retrieve the list of articles under the current category, which can be filtered based on various conditions (such as recommended attributes, sorting methods).
  • {% archiveDetail ... %}In the detail page, get the current article's title, content, images, custom fields, etc.
  • {% pagination ... %}Handle the pagination display of the article list.

The flexible use of these tags allows you to highly customize every detail of the template without directly operating the database.

Some advanced tips and注意事项

  • Existence of template file:Make sure the template filename you fill in the background actually exists and the path is correct.If the template file does not exist, accessing the corresponding page will cause an error, and the page may not open normally.
  • Back-end settings priority:In AnQi CMS, the settings of the 'Category Template' and 'Document Template' fields in the background have the highest priority. If a category conforms to the default naming convention (for example,article/list-10.htmlExists) and the background has specified a custom template (such asarticle/news_list.html), then the specified one by the backgroundarticle/news_list.htmlwill be applied first.
  • Model and category association:When creating a category, the content model it belongs to will be specified (for example, article model, product model).Once specified, the model cannot be changed. This means that your template file should also be named and organized according to the conventions of the model it belongs to, to maintain logical clarity.
  • Single article detail page template override:If you need to set a different detail page template for a specific article that is different from the document template of the category it belongs to, you can find the 'Document Template' field in the 'Other Parameters' when editing the article and fill in the name of the exclusive template file to overwrite it.

By following these steps and techniques, you can easily master the template customization capabilities of AnQi CMS, creating diverse and professional display effects for your website content.


Frequently Asked Questions (FAQ)

Q1: I have set up the category template, but I did not see any changes when accessing the category page, why is that? A1:Please check the following points:

  1. Does the template file exist:Make sure you are/template/您的主题名称/The template file was created in the directory and the filename is consistent with the settings in the background (including case and file extension).
  2. Is the path correct:Ensure you fill in the relative path to the topic directory in the background, for examplearticle/news_list.htmlinstead of/template/您的主题名称/article/news_list.html.
  3. Cache problem:Try clearing the browser cache or click the "Update Cache" feature in the Anqi CMS backend, then visit the page again.

Q2: How do I set a unique detail page template for a single specific article on a website? A2:You can implement it while editing the article. In AnQi CMS backend, go to 'Content Management' -> 'Document Management', find the target article and click 'Edit'.In the 'Other Parameters' area of the article editing page, find the 'Document Template' input box, and enter the custom template file name you designed for this article (such asarticle/special_event_detail.html),then save it.

Q3: What is the specific difference between 'Category Template' and 'Document Template' in terms of usage? A3:

  • Category template:It is mainly used to display a "list" page under a category, such as a news list page, product category list page.It usually cycles through multiple articles' titles, summaries, thumbnails, and includes pagination navigation.
  • Document template:It is mainly used to display the detailed content page of a single article or product.It will display the full content of an article, including the main text, large images, custom fields, comments section, and links to previous and next articles.