As a website operator who is well-versed in Anqi CMS, I know that flexible content management is the key to improving user experience and achieving personalized operation.The powerful functions of AnQi CMS in content model customization are the core weapons that enable us to meet various business needs effortlessly.Today, I will give a detailed explanation of how to customize the content model in AnQiCMS to meet your personalized needs.
The core role of the content model in AnQiCMS
In AnQiCMS, the content model is the foundation for organizing and managing website content.It defines the structure and properties of a certain type of content, for example, an article should include the title, author, publish date, etc., while a product may include the product name, price, inventory information, etc.The Anqi CMS is default built-in with two general models, 'Article Model' and 'Product Model', which cover most of the basic content needs of most websites.However, for specific industries or business scenarios, such as real estate websites needing 'property model', e-commerce platforms needing more detailed 'product model', educational institutions needing 'course model', etc., these default models clearly cannot meet the storage and display of personalized data.
It is precisely to meet the needs of this diversified content structure that AnQiCMS provides a highly flexible content model customization function.Through this feature, you can freely create and expand content types based on your own business logic, ensuring that each piece of content can be managed in the most fitting way according to its attributes, greatly enhancing the adaptability of the system and the efficiency of content operations.
Flexible customization of value embodiment
The value of a customized content model is far more than just storing more types of data.It is directly related to the professionalism of your website content, user experience, and future scalability.Imagine that if you run a used car trading platform and do not have a dedicated "vehicle model", you may need to pack the key information such as "brand", "model", "mileage", "displacement" and so on into some general field of the article, or directly write it into the text.This makes data management chaotic and also makes front-end display, search filtering, and data statistics extremely difficult.
By customizing the content model, you can precisely define unique fields for each special content type.This way, content entry will be more standardized, and operation personnel can clearly see the use of each field;When displaying on the front end, layout and style control can be refined according to custom fields;When retrieving data, it can also be efficiently filtered and queried based on specific fields.This refined content management will directly translate into a better user experience and more efficient operational processes.
Gradually create and define a personalized content model
To start customizing your content model, you first need to enter the AnQiCMS backend management interface.
You can find the 'Content Management' module in the left navigation bar of the background, click to enter, and you will see the option for 'Content Model'. This is the center where you manage all content models.
On the content model management page, you will see the built-in 'article model' and 'product model'.To create a brand new custom model, you need to click the corresponding 'Add Model' button.
When creating a new model, some basic information needs to be filled in:
- Model nameThis is the Chinese name you identify the model in the background management interface, for example, "housing", "course", "recruitment position", etc. It is used for user interface display and navigation in the background.
- Model table nameThis is a key internal identifier that defines the table name where the model content data is stored. The name must beEnglish lowercase lettersIt is unique in the system. For example, if you create a "property model", the model table name can be set to
house_listingPlease note that once set, it is not recommended to modify it arbitrarily to avoid data confusion. - URL aliasThis field will be used for the composition of your website's front-end URL, usually displayed in pseudo-static rules. It must also beEnglish lowercase letterssimple and clear. For example, the housing model can use
houseAs a URL alias, the URL of the relevant page may contain/house/. - Title NameThis is the prompt text for the content title when you publish the model content.For example, when creating a "product model", it can be set to "product name", so that when the product is published, the title field will display "product name" as a prompt.
After completing the basic information entry, the next step is to define the exclusive fields of the model.This is the core of implementing personalized content. On the model editing or new page, there will be a section called "Custom fields of content model".Click “Add field”, you can add any number and type of fields to the model:
- Parameter NameThis is the display name of the field in the background management interface, which is convenient for operation personnel to understand and fill in, such as 'number of bedrooms', 'course duration', 'workplace', and so on.
- Field invocationThis is the unique identifier you use to call this field data in the template. It must beEnglish lowercase lettersAnd it is unique within a model. For example, the field for 'number of bedrooms' can be
bedrooms,'course duration' can beduration. - Field type: AnQiCMS provides various field types to adapt to different data formats:
- Single-line text: Suitable for short text input, such as names, titles, and brief descriptions.
- Number: Only numeric input is allowed, suitable for prices, quantities, areas, etc.
- Multi-line text: Suitable for long text input, such as detailed introductions, notes, etc.
- Single choiceProvide preset options that the user can choose from, such as 'Gender' (male, female), 'House Type' (apartment, villa).The option values are entered one by one through the "Default Value" field.
- Multiple selections: Provide preset options that the user can select multiple, such as "House Features" (furnished, with a balcony, close to subway).The option values are also entered one per line in the 'Default Value' field.
- Drop-down selection: Similar to single selection, but presented in a dropdown menu format, saving page space, suitable for situations with more options, such as "city", "province".Enter the values for the 'Default Value' field one per line.
- Mandatory?You can specify whether this field is required when the content is published.
- Default valueSet the default value for the field. This is where you define all options for radio, checkbox, and dropdown selection types, one per line.
For example, to create a "property model", we can define the fields like this:
- Model name: Property
- Model table name:
property_listing - URL alias:
house - Title name: Property title
Custom field:
- Parameter name: Number of bedrooms, field name:
bedrooms, field type: number - Parameter name: number of bathrooms, calling field:
bathrooms, field type: number - Parameter name: floor area (square feet), calling field:
area_sqft, field type: number - Parameter name: property type, calling field:
property_typeField type: Dropdown selection, default value: Apartment Villa Townhouse - Parameter name: Price, field used:
price, field type: number - Parameter name: Address, field used:
addressField type: Single line text
With such a definition, our 'property model' has highly structured exclusive data fields.
Use custom models in content publishing
After you define and save the new content model, the custom fields will appear accordingly on the "Content Management" page below "Add Document" or "Document Category".
When adding a document, you first need to select the category the content belongs to.It should be noted that each category must and can only be bound to one content model.After you select a category bound to a custom model, the "Other Parameters" collapse box on the page will dynamically display all the custom fields of the model for you to fill in according to the actual content.For example, if you select the "property" category, you can fill in the number of bedrooms, bathrooms, address, price, and other exclusive information in the background.
Display custom data in the front-end template
The most important part of the custom model is how to display these personalized data in the website's front-end template.AnQiCMS powerful template tag system makes this process intuitive.
when you arearchiveDetailOr (document details)archiveListWhen fetching content data in the (document list) tag, the custom fields of the model will be used asitem(or the property name you define) to use.
To display a specific custom field, you can access it directly using dot notation, for example, to display 'Number of Bedrooms':{{item.bedrooms}}(In the list loop){% archiveDetail with name="bedrooms" %}(In the detail page)
If you want to display a list of all custom fields (such as for the product parameter table), you can usearchiveParamsLabel. It allows you to iterate over all custom parameters of the model:
{% archiveParams params %}
<div>
{% for item in params %}
<div>
<span>{{item.Name}}:</span>
<span>{{item.Value}}</span>
</div>
{% endfor %}
</div>
{% endarchiveParams %}
This code will output the 'parameter name' and corresponding 'parameter value' of each custom field.
Furthermore,archiveFiltersThe tag provides the function to filter content on the front end according to custom fields.This is very useful for implementing complex search or category filtering pages.For example, users can filter the list of listings by 'property type' or 'number of bedrooms'.
{# 参数筛选代码,结合archiveList分页列表使用 #}
<div>
<div>房源筛选条件:</div>
{% archiveFilters filters with moduleId="您的房源模型ID" allText="不限" %}
{% for item in filters %}
<ul>
<li>{{item.Name}}: </li>
{% for val in item.Items %}
<li class="{% if val.IsCurrent %}active{% endif %}"><a href="{{val.Link}}">{{val.Label}}</a></li>
{% endfor %}
</ul>
{% endfor %}
{% endarchiveFilters %}
</div>
By combining these tags, you can flexibly display the data of your custom model on any page, achieving highly personalized content display.
**Practice and Precautions
When customizing the content model, there are several**practices worth noting:
- Plan ahead: Be sure to plan in detail the content type and fields required before creating the model and fields. Clear planning can avoid unnecessary modifications and data migration work later.
- Field naming specificationThe 'model_table_name' and the 'call_field' of the custom field are recommended to use full lowercase letters and underscores (snake_case) for naming, for example
house_listingorarea_sqftThis helps maintain the uniformity of the code and avoid potential conflicts. - Choose field types reasonably.Select the most appropriate field type based on the actual data type (for example, use numeric type for price instead of text), which not only ensures data accuracy but also facilitates subsequent data processing and calculation.
- SEO-friendlyWhen customizing URL aliases, choose descriptive and concise English words, which is very helpful for search engine optimization (SEO).
- Performance considerationAlthough the Go language foundation of AnQiCMS ensures high performance, overly complex models or a large number of custom fields may still have a slight impact on database performance.When designing, it should weigh the personalized needs of content and the overall performance of the system.
- Thorough testing: Before using a custom model in a production environment, it is essential to perform thorough content entry, front-end display, search filtering, and other tests in a test environment to ensure that all functions work properly.
By mastering the AnQiCMS content model customization features, you will be able to fully control the structure and display of website content. No matter how special your business is, AnQiCMS can provide strong and flexible support to help you build a website that truly meets your personalized needs.
Frequently Asked Questions (FAQ)
1. What impact will it have if I modify or delete a custom content model?
When modifying an existing model field, if it is only adjusting the field name or display order, it usually will not affect the existing data.If you change the 'call field' or 'field type', or delete a field, the existing content data associated with that field may be lost or may not display correctly.AnQiCMS will prompt you to delete the model, and all documents and categories under the model will also be deleted. Therefore, you must be cautious before performing such operations and make sure to back up your data.
2. Can I reference or use a custom field of another content model in a content model?
In AnQiCMS, the design of the content model is relatively independent.Each content model's custom field belongs only to itself. You cannot directly reference a custom field defined in another model within the content of a model.If you need to implement the association between different model content, you usually do so by linking documents, categorizing associations, or through templates.archiveListTags are queried and displayed across models based on ID, category, and other conditions.
Will creating a large number of custom content models and fields affect website performance?
AnQiCMS is developed in Go language and has the characteristics of high performance and high concurrency. Usually