AnQiCMS as a highly SEO-optimized content management system provides strong support for the search engine performance of website content.Among them, TDK (Title, Description, Keywords, i.e., title, description, keywords) is a core element of SEO optimization. Correctly displaying this information in the website template is crucial for improving the visibility of the website in search engines.This article will introduce how to effectively display these TDK information in AnQiCMS templates.
The importance of TDK information and its setting location
In website development and content operation, TDK information is the important metadata that directly communicates the page theme, content summary, and core keywords to search engines. They are usually placed in the HTML page of<head>The tag has a direct impact on the website's ranking and click-through rate.
In AnQiCMS, the setting of TDK information is very flexible, covering multiple levels such as global, category, single page, article, and tag:
- Global TDK Settings (Home Page TDK)This is the TDK at the website level, mainly used for the homepage.You can configure the homepage TDK settings, including the homepage title, keywords, and description, in the 'Background Settings' -> 'Homepage TDK Settings' section of the AnQiCMS backend.
- Content-level TDK Settings:
- Article/Product Detail PageIn the process of publishing or editing articles/products, you can find the fields of 'SEO title', 'document keywords', and 'document summary' in the 'Add document' or 'Edit document' interface.The 'Document Introduction' is automatically extracted as a description before 150 characters when not set.
- Category PageIn the 'Document Classification' management, when editing a category, you can set 'SEO Title', 'Keywords', and 'Category Description'. The 'Category Description' will also serve as the description information.
- single pageIn the "Page Management
- Tab PageIn the 'Document Tag' management, when editing tags, you can set 'SEO Title', 'Tag Keywords', and 'Tag Description'.
This multi-level setting ensures that each page can have the most accurate and relevant TDK information, thereby enhancing the SEO effect.
Display TDK information in AnQiCMS template
AnQiCMS template system is based on syntax similar to Django, using double curly braces{{变量}}Output the variable, using single curly braces and the percent sign.{% 标签 %}To call the function tag. There are mainly two ways to display TDK information: using universaltdktags or directly accessing the page object properties.
1. Recommend using universaltdktags
AnQiCMS provides a very convenient and powerfultdkUniversal tag, it automatically retrieves and displays the most suitable TDK information according to the type of the current page (home page, category page, detail page, etc.).This greatly simplifies the template code, avoiding complex conditional judgments.
This tag is usually used in HTML pages<head>Part. The following are its main usages:
Page Title (
<title>Tag):<title>{% tdk with name="Title" siteName=true sep=" - " %}</title>Here,
name="Title"Indicates retrieving the page title.siteName=trueIt will append the website name to the title, for example, “Page Title - Website Name”. This is very useful for brand exposure.sep=" - "Can customize the separator between the title and the website name, the default is-.showParent=trueCan be used on category pages, to display the title of the parent category.Page keywords (
<meta name="keywords">Tag):<meta name="keywords" content="{% tdk with name="Keywords" %}">name="Keywords"Will retrieve the keywords of the current page.Page description (
<meta name="description">Tag):<meta name="description" content="{% tdk with name="Description" %}">name="Description"Retrieve the description of the current page. It should be noted that when the page description may contain HTML tags (such as extracted from the abstract), in order to avoid rendering errors on the page, it is usually necessary to配合safeFilter usage:{% tdk with name="Description" %}{{description|safe}}.tdkTags usually automatically handle such escaping, so you can use them directly.Standard link of the page (
<link rel="canonical">Tag)The specification link is very important for avoiding duplicate content and integrating page weight.{%- tdk canonical with name="CanonicalUrl" %} {%- if canonical %} <link rel="canonical" href="{{canonical}}" /> {%- endif %}A conditional judgment is used here, and output is only made when the specification link exists to avoid outputting empty content.
canonicalLabel.
Complete example (base.htmlor the corresponding template's<head>area):
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{# 显示页面标题,并附加网站名称 #}
<title>{% tdk with name="Title" siteName=true sep=" - " %}</title>
{# 显示页面关键词 #}
<meta name="keywords" content="{% tdk with name="Keywords" %}">
{# 显示页面描述 #}
<meta name="description" content="{% tdk with name="Description" %}">
{# 显示规范链接,如果存在的话 #}
{%- tdk canonical with name="CanonicalUrl" %}
{%- if canonical %}
<link rel="canonical" href="{{canonical}}" />
{%- endif %}
{# 其他SEO元标签,如多语言hreflang #}
{%- languages websites %}
{%- for item in websites %}
<link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">
{%- endfor %}
{%- endlanguages %}
{# 可以在这里引入CSS文件 #}
<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">
</head>
<body>
{# 网站内容 #}
</body>
</html>
UsetdkThe benefits of tags lie in their intelligent selection and output of the most accurate TDK information according to the priority set in the AnQiCMS backend (Content Detail Page TDK > Category/Single Page/Tag Page TDK > Global TDK), without the need for you to manually write complex logic in the template.
2. Direct access to object properties on specific content pages
In detail pages, category pages, single pages, or tag pages, and other specific types of pages, you can directly access the corresponding data object of the current page (such asarchive/category/page/tagThe TDK-related attributes. This approach is suitable when you need to control or combine TDK information more finely, or whentdkthe tag does not meet specific requirements.
- Article/Product Detail Page:
In the article (
archive) or product