As an old soldier who has been deeply involved in website operations for many years, I know that every detail can affect the performance of a website in search engines.Among them, Title (title), Description (description), and Keywords (keywords) - commonly known as TDK, are the foundation of website SEO optimization.They are like the 'front door' and 'map' of a website, directly telling search engines and users what your page is about.

In AnQiCMS (AnQiCMS) such an efficient and customizable Go language content management system, customizing the display logic of TDK is not only flexible and convenient, but also helps us finely control the SEO strategy.Today, let's delve into how to cleverly customize the display logic of these key elements in the AnQiCMS template.

AnQiCMS TDK strategy: layered and flexible

AnQiCMS provides a hierarchical, step-by-step coverage strategy in TDK management, greatly enhancing our operational flexibility.This means that you can fine-tune the TDK for every page of the website from macro to micro.

First, inGlobal SettingsIn Chinese, you can configure TDK for the homepage of the entire website.This is usually a reflection of your brand name, core business, and overall positioning.In the "Homepage TDK settings

Furthermore, AnQiCMS allows you toat the content levelSet independent TDK for each specific content (such as articles, products, single pages, category pages, and tag pages).For example, when publishing a document, in addition to the article title and content, you will find special fields such as 'SEO Title', 'Document Keywords', and 'Document Summary'.The purpose of these fields is to allow you to optimize the search engine visibility of each piece of content specifically.Similarly, in "Document Classification

The elegance of this layered design lies in the fact that when a page has both global TDK and content TDK, the content-level TDK is often read first, thereby achieving more precise SEO control. The final TDK presented to the user is determined by yourTemplate codeDecide how to parse and display these data.

Core Tool: Universal TDK Tag{% tdk %}Exquisite application

The AnQiCMS template system uses a syntax similar to the Django template engine, one of the very powerful built-in tags being{% tdk %}. It is designed as a 'universal tag' that can intelligently capture and output the corresponding TDK information according to the current page type (home page, article page, category page, etc.).

Customization of Title (Page Title)

in the template's<head>area, you can use{% tdk with name="Title" %}Output the page's Title tag content.This label is very intelligent, it will try to get the content level (such as articles, categories, single-page SEO titles) according to the context of the current page first, and if it is not set, it will fall back to the general title of the content, and finally fall back to the global home page title.

What's even better is,{% tdk name="Title" %}and also provides several practical parameters:

  • siteName=trueIf you want the website name to be automatically appended to the page title, you can set it totrueFor example,{% tdk with name="Title" siteName=true %}It may output 'Article Title - Your Website Name'.
  • sep="_"You can customize the separator between the website name and the page title, for example, set it to an underscore_.
  • showParent=true: Under some category pages, you may want the Title to display the title of the parent category, and this parameter can help you achieve that.

For example, in yourbase.htmlHeader:

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

Control of Keywords (page keywords) and Description (page description)

For Keywords and Description, the usage is similar to Title:

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

They will also match intelligently based on the page context, prioritizing keywords and descriptions set at the content level, followed by their regular introduction, and finally falling back to the global settings.

The introduction of Canonical Url (standard link)

In SEO, standard linksCanonical UrlAre crucial for handling duplicate content. AnQiCMS also provides{% tdk with name="CanonicalUrl" %}The link to display the page standard. When content is published, if the article or single page is set to standard link, it will be output here. **Practical condition judgment:

{%- tdk canonical with name="CanonicalUrl" %}
{%- if canonical %}
<link rel="canonical" href="{{canonical}}" />
{%- endif %}

This ensures that the label is only output when there is a standard link, keeping the code tidy.

Practical exercise in customizing TDK display logic.

Though{% tdk %}The tag is already smart, but in some specific business scenarios, we may need a more refined and prioritized TDK display logic.AnQiCMS's template flexibility allows us to directly write judgments in the template and customize the process of retrieving data.

Assuming you want to implement such logic on the article detail page:

  1. Use the article's own 'SEO title' first.
  2. If the "SEO title" is empty, then use the article's "Document title".
  3. Finally, add the website name uniformly.

You can use the article detail template (such asarchive/detail.html)的<head>parts are written like this:

`html {% set pageTitle = "

{% set pageTitle = seoTitle %}

{% else %}

{# 如果SEO标题为空,则获取文章的常规标题 #}
{% archiveDetail articleTitle with name="Title" %}
{% set pageTitle = articleTitle %}

{% endif %}

{# Get the website name #} {% system siteName with name=“SiteName” %}

{# Combined Final Title #}