{dede:field.typeurl/} 是什么标签?

99ANYc3cd6
预计阅读时长 17 分钟
位置: 首页 DEDE建站 正文

Of course. Let's break down what {dede:field.typeurl/} is, what it does, and how to use it.

{dede:field.typeurl/
(图片来源网络,侵删)

Summary

{dede:field.typeurl/} is a DedeCMS template tag that is used to display the full URL of the current article's category.

It is most commonly used within the context of an individual article template (e.g., article_article.htm) to link back to the category from which the article was published.


Detailed Explanation

What It Does

When you are viewing a single article on your DedeCMS website, that article belongs to one specific category. The {dede:field.typeurl/} tag automatically fetches the URL of that category and outputs it as a complete, clickable link.

Where to Use It

You should place this tag inside a template file that is used to display a single article. The most common file is:

{dede:field.typeurl/
(图片来源网络,侵删)
  • /templets/default/article_article.htm

It is often used to create a "breadcrumb" link, a "back to category" link, or simply to display the category name as a hyperlink.

Basic Syntax and Example

The tag is very simple to use. By default, it just outputs the URL.

Basic Usage (outputs the URL only):

<a href="{dede:field.typeurl/}">View Category</a>

More Common Usage (outputs the category name as a link):

{dede:field.typeurl/
(图片来源网络,侵删)

Often, you'll want the link text to be the name of the category, not just "View Category". For this, you can combine it with the {dede:field.type/} tag, which outputs the name of the category.

<a href="{dede:field.typeurl/}">{dede:field.type/}</a>

When rendered on the page, this code would produce something like: <a href="https://www.yoursite.com/news/">News</a>

Advanced Usage with Parameters

The tag also accepts a parameter to change its behavior.

The function parameter

You can use the function parameter to apply a PHP function to the output. A very common use case is to make the URL compatible with "HTML static" (.html) files, which is a standard feature in DedeCMS.

Example: Creating an HTML-compatible Category Link

If your site uses HTML static pages, the category URL might normally be .../category/1/. Using the GetMkTypeUrl function ensures it becomes .../category/1.html.

<a href="{dede:field.typeurl function='GetMkTypeUrl(@me)'}">{dede:field.type/}</a>
  • function='...': This tells DedeCMS to run a PHP function on the tag's output.
  • @me: This is a special variable that represents the original output of the tag (the URL).
  • GetMkTypeUrl(): This is the built-in DedeCMS function that converts a dynamic URL into its static HTML equivalent.

Practical Use Case: Creating a Breadcrumb

A breadcrumb navigation helps users understand where they are on the site and allows them to navigate back up the hierarchy. Here’s how you could use {dede:field.typeurl/} to build a simple breadcrumb in your article_article.htm template.

<div class="breadcrumb">
    <a href="{dede:global.cfg_basehost/}">Home</a> &raquo;
    <a href="{dede:field.typeurl function='GetMkTypeUrl(@me)'}">{dede:field.type/}</a>
</div>

How this would look on the page:

If you are on an article in the "Technology" category, the HTML output would be:

<div class="breadcrumb">
    <a href="https://www.yoursite.com/">Home</a> &raquo;
    <a href="https://www.yoursite.com/tech/">Technology</a>
</div>

Or, if you are using HTML static files:

<div class="breadcrumb">
    <a href="https://www.yoursite.com/">Home</a> &raquo;
    <a href="https://www.yoursite.com/tech.html">Technology</a>
</div>

Important Considerations

  • Context is Key: This tag will not work outside of the context of an article page. If you try to use it in your homepage template (index.htm) or a category list template (list_category.htm), it will either output nothing or cause an error, because there is no "current article" to get a category from.
  • DedeCMS Version: While this tag has been a core part of DedeCMS for a very long time, always test it in your specific version of DedeCMS to ensure it behaves as expected.
  • SEO and Usability: Using this tag to create clear links back to the category is excellent for both user experience (UX) and Search Engine Optimization (SEO). It helps users and search engines understand the content's structure and relationship to other pages.
-- 展开阅读全文 --
头像
linux c语言连接mysql数据库
« 上一篇 11-28
Windows下C语言如何调用Python脚本?
下一篇 » 11-28

相关文章

取消
微信二维码
支付宝二维码

目录[+]