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, that is, title, description, keywords) is a core element of SEO optimization. Properly 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 the AnQiCMS template.

The importance of TDK information and its placement

In website development and content operation, TDK information is the important metadata that directly conveys the page topic, content summary, and core keywords to search engines. They are usually placed in the HTML page's<head>The tag has a direct impact on the ranking and click-through rate of the website.

In AnQiCMS, the TDK information setting is very flexible, covering global, category, single page, article, and tag levels and more:

  1. Global TDK Settings (Home TDK)This is the TDK at the website level, mainly used for the homepage.You can configure it in the "Background Settings" of AnQiCMS -> "Home TDK Settings", including the home title, keywords, and description.
  2. Content Level TDK Settings:
    • Article/Product Details PageWhen publishing or editing articles/products, you can find the 'SEO Title', 'Document Keywords', and 'Document Description' fields in the 'Add Document' or 'Edit Document' interface.In which, the 'Document Summary' is automatically extracted as a description with the first 150 characters of the content if not set.
    • Category PageIn the document category management, when editing a category, you can set the 'SEO title', 'keywords', and 'category description.' The 'category description' will also serve as the description information.
    • single pageIn the "Page Management" section, when editing a single page, you can set "SEO Title", "Keywords", and "Single Page Description".
    • 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 improving SEO effectiveness.

Display TDK information in AnQiCMS template

AnQiCMS template system is based on syntax similar to Django, using double curly braces{{变量}}To output variables, use single curly braces and percent signs{% 标签 %}To call the function tag. There are mainly two ways to display TDK information: using the universaltdktag or directly accessing the page object properties.

1. It is recommended to use the universaltdkTag

AnQiCMS provides a very convenient and powerfultdkThe universal tag, it can automatically obtain and display 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 the HTML page<head>part. The following are its main uses:

  • Page title (<title>Label):

    <title>{% tdk with name="Title" siteName=true sep=" - " %}</title>
    

    here,name="Title"means to get 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, displaying the title of the parent category.

  • Page keywords (<meta name="keywords">Label):

    <meta name="keywords" content="{% tdk with name="Keywords" %}">
    

    name="Keywords"Will get the keywords of the current page.

  • Page description (<meta name="description">Label):

    <meta name="description" content="{% tdk with name="Description" %}">
    

    name="Description"The description of the current page will be obtained. It should be noted that when the page description may contain HTML tags (such as extracted from the summary), in order to avoid page rendering errors, it is usually necessary to cooperate withsafeThe filter is used:{% tdk with name="Description" %}{{description|safe}}ButtdkTags usually automatically handle this kind of escaping, so they can be used directly.

  • The standard link of the page (<link rel="canonical">Label): Standard links are 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 was used, only output when the standard link exists to avoid empty outputcanonical.

A complete example(base.htmlOr the corresponding template's<head>the 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 benefit of tags is that they intelligently select and output 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. Directly access object properties on a specific content page

In the article detail page, category page, single page, or tag page, etc., you can directly access the corresponding data object of the current page (such asarchive/category/page/tagThe TDK-related attributes. This method is suitable when you need to control or combine TDK information more finely, or whentdkthe tag does not meet specific requirements.

  • Article/Product Details Page: In the article (archive) or product