As an experienced website operator who deeply understands the operation of AnQiCMS, I know that the accuracy and efficiency of obtaining the current page content is crucial for the daily management and optimization of the website.AnQiCMS provides intuitive and powerful template tags, allowing us to easily extract the required document title, specific content, and standard link from the currently loaded page.This not only helps us achieve fine control in front-end display, but also provides a solid foundation for SEO optimization.
Get the document title of the current page
The document title of the current page usually has two levels of meaning: one is HTML<title>The page title displayed to search engines and browsers users, which is crucial for SEO; it is also the main identifier of the document or article title in the main content of the page.
for HTML's<title>tags, AnQiCMS providestdktags, we can use{% tdk with name="Title" %}A way to dynamically retrieve the title of the current page. This tag automatically generates the most appropriate title based on the type of the current page (document, category, single page, etc).It also supports throughsiteName=trueto automatically append the site name throughsepto customize the separator, andshowParent=trueParameters to display the parent category title, all of these are automatically adjusted according to the backend configuration.
When it is necessary to display the specific title of a document or article in the page content area, we can use the detail tags of a specific content type. For example, if the current page is an article or product detail page, then we usearchiveDetailtags, through{% archiveDetail with name="Title" %}You can obtain the title. Similarly, for a single page, we can use{% pageDetail with name="Title" %}; for category pages, it uses{% categoryDetail with name="Title" %}; for tag pages, it uses{% tagDetail with name="Title" %}These tags will default to the title of the current page's document, single page, category, or tag if no ID or token is specified.
This is a brief example of getting the page title:
{# 获取HTML头部标题,并附加网站名称 #}
<title>{% tdk with name="Title" siteName=true %}</title>
{# 在页面主体内容中显示文章标题 #}
<h1>{% archiveDetail with name="Title" %}</h1>
Extract the specific content of the current page
The main content of the current page is the core requirement for building dynamic web pages. The detail tag of AnQiCMS can accurately extract detailed information of various contents.
For article or product detail pages, we usearchiveDetailtags, through{% archiveDetail with name="Content" %}You can get the full content of the document. This tag is very flexible when outputting content.For example, if the content contains HTML tags, in order to ensure that they are rendered correctly rather than as plain text, it is usually necessary to accompany with|safea filter such as{{ archiveContent|safe }}. In addition, if the content includes images, we can also make use oflazy="data-src"Implement lazy loading of images with attributes to enhance page performance. When the Markdown editor is enabled on the back end, the content is automatically converted to HTML; if manual control of the conversion behavior is needed, you can userender=trueorrender=falseParameter.
Similarly, if the current page is a single page, we can use{% pageDetail with name="Content" %}to get its content; for category pages, use{% categoryDetail with name="Content" %}; for tag pages, it uses{% tagDetail with name="Content" %}. These tags also support|safeFilter and Markdown rendering control.
Here is an example of getting the content of the page:
{# 获取文章主体内容,并确保HTML正确渲染 #}
<div>
{%- archiveDetail articleContent with name="Content" lazy="data-src" render=true %}
{{articleContent|safe}}
</div>
Get the link address of the current page
The link address of the current page is also an indispensable part of website navigation and SEO strategy. AnQiCMS provides multiple ways to obtain the standard URL of the current page.
The most direct way is to use a specific content type detail tag. For example, for articles or product detail pages, we can through{% archiveDetail with name="Link" %}To get the absolute or relative link on the website. Similarly, for a single page, use{% pageDetail with name="Link" %}; For category pages, use{% categoryDetail with name="Link" %}; For tag pages, use{% tagDetail with name="Link" %}These links are automatically generated based on the pseudo-static rules and content structure of the current page.
In addition, for SEO, it is crucial to set up a canonical link (Canonical URL), which can inform search engines of the preferred version of the current page, avoiding duplicate content issues. AnQiCMS throughtdkThe label provides this feature, we can use{% tdk with name="CanonicalUrl" %}To obtain the specification link of the current page. In the template, we usually judge whether this specification link exists, and if it exists, we place it in the HTML's<head>Within the area.
This is an example of getting a page link:
{# 获取文章的URL,可用于导航或分享按钮 #}
<a href="{% archiveDetail with name="Link" %}">阅读更多</a>
{# 在页面头部设置规范链接 #}
{%- tdk canonical with name="CanonicalUrl" %}
{%- if canonical %}
<link rel="canonical" href="{{canonical}}" />
{%- endif %}
Through these flexible and intelligent template tags, AnQiCMS enables website operators to efficiently manage and present content, making it effortless whether it's optimizing page titles to improve search rankings, precisely controlling content display to enhance user experience, or ensuring the规范性 of page links to maintain website health.Mastering the use of these tags is the key to unleashing the potential of AnQiCMS content management.
Frequently Asked Questions
AnQiCMS detail tag (such as)archiveDetail/pageDetail/categoryDetail/tagDetail) if not explicitly specifiedidortokenWhen the parameter is set, it will automatically identify the type of content currently displayed on the page and extract the corresponding fields of the content.The system intelligently judges the core entity of the current page through URL paths, routing rules, and internal context information, thereby automatically obtaining its associated data.
You can explicitly specify in the detail tagidortokenParameters to retrieve data from non-current pages. For example, if you want to display the title of another specific article on the article detail page, you can use{% archiveDetail with name="Title" id="123" %}of which123Is the ID of the target article. In this way, you can call any specified type of data on any page to achieve more complex page layout and content aggregation.
tdkThe tag is mainly used to retrieve metadata related to the entire page, such as HTML<title>/<meta name="keywords">/<meta name="description">as well as<link rel="canonical">. This information is for the entire page rather than for a specific content item within the page. AndarchiveDetail/pageDetailTags then focus on obtaining the page inCore content entity(For example, an article or a product) has detailed fields such as its title, main content, and its own link. In practice, they work together:tdkTags are usually used in the HTML header, affecting search engine inclusion and browser display; while content detail tags are used in the main body of the page, to display the specific information that the user is browsing.