In daily website operations, we often encounter the need to publish various types of content.In addition to common articles and product displays, you may also need a dedicated 'event list' to post the latest activities, or a 'team members' page to showcase the core team of the company, and even a 'successful case' module to share project experience.AnQiCMS (AnQiCMS) has fully considered this flexibility in its design, providing powerful custom content model functions, allowing us to flexibly create and manage different types of content structures according to our actual business needs.
How can you create and manage these custom content models in Anqi CMS, and add dedicated fields for them? It's actually simpler than you might think.
Build your content skeleton: Understand and create custom content models
The content model can be understood as the 'skeleton' or 'blueprint' of different types of content.It defines what basic information each content should contain, such as an event model may need "event title", "start time", "location", "registration link", and so on.The Anqi CMS provides the basic skeletons of 'Article Model' and 'Product Model' by default, which meet most common needs.When your content needs become more diverse, the value of a customized content model becomes evident.
To start creating, we first need to enter the Anqi CMS backend management interface.In the navigation menu on the left, find the "Content Management" module and then click to enter the "Content Model" option.Here, you will see the list of built-in models in the system, as well as a 'Add New Model' button.
Click 'Add new model' and you will face several key settings:
- Model name:This is a user-friendly display name, such as 'Activity Model' or 'Team Member'. It will appear in various content management entry points in the background, making it easy to identify and operate.
- Model table name:This is the table name where the system stores the model data in the database. Please note that it must useEnglish lowercase lettersThis is to ensure the standardization and stability of the database. Once set, it is usually not recommended to change it arbitrarily, as it is directly associated with your data storage.
- URL alias:This field also needs to be used.English lowercase lettersIt is mainly used as a model layer identifier when generating pseudo-static URLs.A clear and concise URL alias helps improve SEO effect and user experience.For example, setting "activity" as the URL alias for the "activity model" means that the URLs of related pages may contain
/activity/. - Title Name:This setting is very considerate. It defines the prompt text for the main content field when you create content under the model.For example, in the "event model", you can set it to "event topic", so when publishing an event, the main title input box will display the hint "event topic", making the operation more intuitive.
After completing these basic settings, your content model skeleton is set up.But to truly 'come alive' this skeleton, we need to add specific 'flesh' - that is, dedicated fields.
Detail injection: Add specific fields to the custom model
The strength of the model lies in its ability to flexibly define various data fields to meet the storage needs of different content types.When creating or editing a content model, you will find the 'Content Model Custom Fields' area at the bottom of the page.Here, you can add, edit, or delete the exclusive fields of the model.
Click 'Add field' to open a new form that allows you to define this field in detail
- Parameter name:This is the display name of this field, such as 'Event Location', 'Registration Deadline', or 'Member Position'.It will be displayed on the background content editing page, making it convenient for editors to understand and fill in.
- Call field:This is the variable name used when calling this field in the front-end template, and it also corresponds to the actual field name in the database. It is recommended to useEnglish lowercase lettersFor example, 'location', 'deadline', or 'position'. In the template, you can pass through
{{archive.location}}This way to obtain and display data. - Field type:AnQi CMS provides various field types to adapt to different data formats:
- Single-line text:Suitable for short text inputs, such as titles, names, etc.
- Number:Only allows input of numbers, suitable for prices, quantities, etc.
- Multi-line text:Fields that require input of a lot of content are applicable, such as event introductions, member profiles, etc.
- Single choice:Allow editors to select one from the predefined multiple options.
- Multiple selection:Allow the editor to select multiple options from the predefined set.
- Dropdown selection:Similar to single selection, but displayed in a dropdown menu to save page space.
- For the 'Single choice', 'Multiple choice', and 'Dropdown selection' types, you also need to enter an option on each line in the 'Default value' field to define the available options.
- Mandatory?:If checked, this field must be filled in when publishing content; otherwise, it cannot be submitted. This helps ensure the completeness of the content.
- Default:If this field usually has a fixed value, or options are defined in a selection type field, they can be preset here. Leaving it blank indicates no default value.
By following these steps, you can add any number and type of fields to each custom content model, precisely matching your content needs.
Actual application of content models
After you have set up your custom content model and fields, their value will be fully reflected in content operations.
Firstly, when creating new content, you need to select a "category", and each category is associated with a content model.Once you have selected the corresponding category, the content editing interface will automatically load all the custom fields defined under the content model.This way, editors can accurately fill in the information based on field prompts, ensuring that all content is organized according to the preset structure.
Secondly, when designing front-end templates, you can make use of the powerful template tag system of Anq CMS (for examplearchiveDetailandarchiveParamsLabels), easily call these custom field data and display them on the website. Whether it's showing a location of an event or a position of a team member, it can be done flexibly.
By using a custom content model, Anqi CMS not only helps us achieve personalized content display, but also greatly improves the website's adaptability to various business needs, making content management more efficient and orderly.
Frequently Asked Questions (FAQ)
1. What is the difference between a custom content model and the built-in "article/product model"? Which should I choose?
The custom content model provides high flexibility, allowing you to design exclusive content structures and fields according to specific business scenarios (such as events, team members, cases, etc.)And the built-in "article model" and "product model" are preset general structures, suitable for most blog articles and product displays.If the content type is significantly different from the article or product, or if specific information needs to be captured, creating a custom model would be a better choice, as it can make your data structure clearer, more convenient to manage, and more targeted when displayed on the front end.If your content overlaps with the article or product, you can directly use the built-in model, and you can skip the custom steps.
2. How should I call the custom field I created in the front-end template?
The custom field is usually very intuitive when called in the front-end template. If you create the field in the background, its "call field" is set toauthor_nameThen in the article detail page template, you can directly go through{{archive.author_name}}To get the value of the field. If you want to traverse all the names and values of custom fields in a document, you can use{% archiveParams params %}...{% endarchiveParams %}Tag to get. The specific usage suggestions refer to the Anqi CMS template development document aboutarchiveDetailandarchiveParamsDetailed explanation of the tag, with very clear examples.
What are the risks of modifying the "model table name" or "URL alias" of the content model?
There is a certain risk in modifying the "model table name" or "URL alias", especially when the website has been launched and there is a large amount of data.
- Model table name:It is the actual table name where data is stored in the database. Modifying it may cause the system to be unable to find the original data, resulting in data loss or page errors.Therefore, once set, it is strongly recommended not to change it.
- URL alias:It is used to generate the page URL identifier. Changing it will cause the URL of all the content under the model to change.This will affect the website's SEO (search engine optimization) because search engines will consider these pages to be new or missing, which may lead to a decrease in traffic.If indeed a modification is needed, it is imperative to use the 301 redirect feature to permanently redirect the old URL to the new one, in order to minimize SEO impact.