As an experienced CMS website operation personnel in the security industry, I know that it is crucial to correctly call content links in templates for the user experience of the website and search engine optimization.The single page is a key part carrying static information such as "About Us" and "Contact Information", and the accurate invocation of its link is an indispensable part of daily operation.
Below I will elaborate on how to correctly call single-page links in the Anqi CMS template.
Understand single-page links in Anqi CMS
In Anqi CMS, a single page (or known as "page") exists independently of content models such as articles, products, and so on.Each single page created in the background will generate a unique identifier (ID) and an optional "custom URL" (URL alias).This information is the basis for correctly calling its link in the template.{{变量}}Output the variable value and support fetching data through specific tags.
Call the link of a specific single page.
When you need to reference a single-page link at a fixed position in a template, such as the website navigation, footer, or sidebar,Specificyou can usepageDetailThis tag allows you to accurately obtain the detailed information of a page by its single-page ID or its URL alias, including its link.
UsepageDetailwhen labeling, you can specifyidortokenParameters to locate the target single page and access it.name="Link"Parameters to extract its URL.
Here is an example of calling a specific single page link:
{# 假设我们已知“关于我们”页面的ID是1 #}
<a href="{% pageDetail with name='Link' id='1' %}">关于我们</a>
{# 假设“联系我们”页面的URL别名(token)是“contact-us” #}
<a href="{% pageDetail with name='Link' token='contact-us' %}">联系我们</a>
{# 您也可以将链接赋值给一个变量,再使用 #}
{% pageDetail aboutUsLink with name='Link' id='1' %}
<a href="{{ aboutUsLink }}">关于我们</a>
In these examples,name='Link'Explicitly tell the CMS template engine that we want to retrieve the external link of this single page.The system will automatically generate a complete and accessible URL based on the "custom URL" in the background and the pseudo-static rules of the website.
List of links to batch call single pages.
If you need to display multiple single-page links in a loop, such as in a sitemap or a 'Featured Pages' list,pageListtags will be your ideal choice.pageListThe tag will return an array object containing all single-page information, you can access it throughforloop through this array and get the link of each single page.
The following is an example of a batch call to a single-page link list.
<nav class="footer-pages-nav">
<ul>
{% pageList pages %}
{% for item in pages %}
{# item.Link 会输出当前单页面的链接 #}
<li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
{% endfor %}
{% endpageList %}
</ul>
</nav>
In this example,pageListAll available single pages have been retrieved.for item in pagesThe structure processes each single page sequentially.{{ item.Link }}The variable will output the current single page URL in each loop{{ item.Title }}and then output the page title, convenient for you to build a dynamic page list.
An important consideration when calling the template
When calling single-page links in templates, there are several practices and backend configurations that you need to pay attention to in order to ensure the accuracy of the links and the overall performance of the website:
Firstly,Custom URL settingsLinks on a single page play a decisive role.In the "Page ManagementpageDetailandpageListLabel outputLinkValue, it is recommended that you set a concise and meaningful custom URL for important pages, which is very beneficial for SEO optimization and user memory.
Secondly,The use of single-page template filesis also a key point. Anqicms allows you to specify a custom template for single-page, such aspage/detail.htmlthe default template, orpage/{单页ID}.htmleven manually specified in the backgroundpage/about.html.LinkThe label outputs the URL to access these pages, not the path of the template file itself.
Finally, if you are operating anQi CMS in a multi-site environment and need to reference a single-page link from another site,pageDetailandpageListtags are supportedsiteIdparameters.siteIdYou can explicitly specify which site to obtain single-page data from, thereby implementing cross-site link calls.
By using the above method, you can flexibly and efficiently call single-page links in the Anqi CMS template. Whether it is an accurate reference to a single page or a list display of multiple pages, it can be easily realized, thereby enhancing the overall navigation and user experience of the website.
Common Questions and Answers (FAQ)
Q1: My single-page link is displayed incorrectly in the template, how should I investigate the problem?
A1: If the single page link is displayed incorrectly, please first check whether the 'custom URL' setting of the single page in the 'Page Management' section of the Anqi CMS backend meets your expectations. This is the basis for generating links.Next, go to the "Function Management" under the "URL Rewrite Rule" page, confirm whether the URL rewrite rule for a single page is correctly configured and effective.Incorrect rewrite rules can cause links to be improperly resolved.
Q2: Can I display a single-page link with a specific ID or meet specific conditions within a loop?
A2: Absolutely. When usingpageListLabel retrieval of the single page list, you can thenforCombine within a loop.ifLogical judgment of the label for filtering. For example, you can write the code like this to only display single page links with ID 5 and ID 10:
{% pageList pages %}
{% for item in pages %}
{% if item.Id == 5 or item.Id == 10 %}
<li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
{% endif %}
{% endfor %}
{% endpageList %}
Q3: How to insert images or videos in a single page and call these media contents in the template?
A3: The main content of the single page (ContentField) is edited through the rich text editor in the background. You can directly insert images or videos into the editor. If the page is configured with media resources such as 'Banner image' or 'thumbnail', you can use them in the template.pageDetailLabel them to call them. For example,