Tuts+ Guide to the Eighth Batch of Template Tags
In part eight of this series, we looked at the seventh batch of WordPress template tags. In Part 9, we'll take a look at the final batch of nearly 200 template tags. Throughout this tutorial we'll see template tags for bookmarks as well as other "miscellaneous" template tags.
Warning about Bookmarks: Starting with WordPress 3.5, “Bookmarks” are hidden by default in the admin panel. To use bookmarks, you need to install the link manager plugin.
Get and display the bookmark list: wp_list_bookmarks()
This template tag returns or echoes a list of bookmarks, which is an old feature of WordPress.
parameter
This template tag accepts only one parameter:
-
<li>
- ')
$args
(optional - array) : Array of the following parameters:
-
<li>
'orderby'
(String): How to order bookmarks. Accepts "name", "link_id", "url", "target", "description", "owner" (user who added the bookmark), "rating", "update" (date updated), "rel" (XFN) bookmark relationship), 'notes', 'rss', 'length' (bookmark name length), 'rand' (random). (Default: 'name')
<li>'order'
(string): Whether to sort items in ascending ('ASC') or descending ('DESC') order. (Default: 'ASC')
<li>'limit'
(integer): Number of items to display. (Default: -1 means all bookmarks)
<li>'category'
(String): Comma-separated category IDs from which to get items. (Default: ' ' means all categories)
<li>'exclude_category'
(String): ID of the bookmark category to exclude. (default:' ')
<li>'category_name'
(string): Display the bookmark's category name (overrides 'category'). (default:'')
<li>'hide_invisible'
(integer): Whether to hide invisible links or show them. (Default: 1)
<li>'show_updated'
(integer): Whether to display the last updated timestamp. (Default: 0)
<li>'echo'
(integer): Whether to echo the output (1) or return it (0). (Default: 1)
<li>'categorize'
(integer): Whether to group bookmarks by category (1) or not (0). (Default: 1)
<li>'title_li'
(string): Wrap the output with <li>
tags and display the title before the bookmark list. You may want to set it to an empty string and disable newlines. (Default: "Bookmark")
<li>'title_before'
(string): HTML code to add before each title. (default:'')
'title_after'
(string): HTML code added after each title. (default:'')
<li>'class'
(string): CSS class name to add to each category. (Default: 'linkcat')
<li>'category_before'
(string): HTML code to add before each category. (default:'
'category_after'
(string): HTML code added after each category. (default:'
')'category_orderby'
(String): How to sort categories. Accepts "name", "id", "slug" and "count". (default: "name")
<li>'category_order'
(string): Whether to sort categories in ascending ('ASC') or descending ('DESC') order. (Default: 'ASC')
usage
<?php $args = array( // Random order. 'orderby' => 'rand', // Take just 5 bookmarks. 'limit' => 5, // Take bookmarks from a specific category. 'category_name' => 'Friends', // Don't echo. 'echo' => 0, // Custom class. 'class' => 'friends-bookmark-list' ); $bookmarks_list = wp_list_bookmarks( $args ); ?>
Get the array of all bookmarks: get_bookmarks()
This template tag returns an array of WordPress bookmarks.
parameter
This template tag accepts only one parameter:
-
<li>
$args
(optional - array) : Array of the following parameters:
-
<li>
'orderby'
(String): How to order links. Accepts post fields such as Name, ID, Title, Date, etc. (default: "name")
<li>
'order'
(string): Whether to sort items in ascending ('ASC') or descending ('DESC') order.
(Default: 'ASC')
<li>
'limit'
(integer): Number of items to display.
(Default value: -1 means all)
<li>
'category'
(String): Comma-separated category IDs from which to get items.
(default: empty)
<li>
'category_name'
(String): Category name to get the item from.
(默认:空)
<li>
'hide_invisible'
(整数或布尔值):是否显示或隐藏标记为“不可见”的链接。
(默认:1|TRUE
)
<li>
'show_updated'
(整数或布尔值):是否显示书签上次更新时间。
(默认:0|FALSE
)
<li>
'include'
(字符串):要包含的以逗号分隔的 ID 列表。
(默认:空)
<li>
'exclude'
(字符串):要排除的 ID 的逗号分隔列表。
(默认:空)
用法
<?php $args = array( 'orderby' => 'title', 'order' => 'ASC', 'limit' => 15, 'hide_invisible' => false, 'exclude' => '12,16,23' ); $bookmarks_array = get_bookmarks( $args ); ?>
获取书签数据:get_bookmark()
此模板标记返回给定书签的所有数据。
参数
此模板标记接受三个参数:
-
<li>
$bookmark
(必需 - 混合):书签 ID 或对象。
(默认:NULL
) >
<li>
$output
(可选 - 字符串):
OBJECT、ARRAY_N 或 ARRAY_A 常量。
(默认:OBJECT
)
<li>
$filter
(可选—字符串):
是否转义输出。如果您想过滤输出,请将其设置为“display”。
(默认:“raw”)
用法
<?php // Getting a specific bookmark's fields with escaping the output. $bookmark_data( 19, OBJECT, 'display' ); ?>
获取单个书签字段的数据:get_bookmark_field()
此模板标记可让您获取单个书签字段的数据。
参数
此模板标记接受三个参数:
-
<li>
$field
(必填—字符串):字段名称。
(默认:NULL
)
<li>
$bookmark
(必需 — 整数):
书签 ID。
(默认:NULL
)
<li>
$context
(可选—字符串):
如何过滤字段值—“raw”、“edit”、“attribute”、“js”、“db” ',或'显示'。
(默认:'显示')
用法
<?php // Get the bookmark with the id 16 and escape & echo its title. echo get_bookmark_field( 'title', 16, 'display' ); ?>
获取并显示“编辑书签”链接:get_edit_bookmark_link()
& edit_bookmark_link()
这些模板标签可让您获取或回显“编辑此书签”链接以在模板中使用。
参数
get_edit_bookmark_link()
只接受一个参数:
-
<li>
$bookmark_id
(必需 - 整数):书签的 ID。
(默认:0)
而 edit_bookmark_link()
接受四个参数:
-
<li>
$text
(可选—字符串):显示链接的文本。
(默认:“编辑此”) EM>
<li>
$before
(可选—字符串):
在输出之前显示的文本或 HTML 代码。
(默认:空)
<li>
$after
(可选—字符串):
输出后显示的文本或 HTML 代码。
(默认:空)
<li>
$bookmark_id
(必需 - 整数):
书签的 ID。
(默认:NULL
) >
用法
<?php // Retrieve the current bookmark's "edit bookmark" link. $edit_bookmark_link = get_edit_bookmark_link(); // Retrieve a specific bookmark's "edit bookmark" link. $edit_bookmark_link = get_edit_bookmark_link( 98 ); // Display the current bookmark's "edit bookmark" link. edit_bookmark_link( __( 'Edit', 'translation-domain' ), '<strong>', '</strong>' ); // Display a specific bookmark's "edit bookmark" link. edit_bookmark_link( __( 'Edit', 'translation-domain' ), '', '', 98 ); ?>
获取并显示您网站的信息:get_bloginfo()
& bloginfo()
这些非常流行的模板标签返回并显示您网站的一般信息。
参数
get_bloginfo()
接受两个参数:
-
<li>
$show
(可选—字符串):要获取的信息位。以下值之一:
-
<li>
'url'
(字符串):主页 URL。
<li>
'wpurl'
(字符串):安装 WordPress 的 URL。
<li>
'description'
(字符串):站点描述。
<li>
'rdf_url'
(字符串):RDF/RSS 1.0 提要 URL。
<li>
'rss_url'
(字符串):RSS 0.92 提要 URL。
<li>
'rss2_url'
(字符串):RSS 2.0 提要 URL。
<li>
'atom_url'
(字符串):Atom 提要 URL。
<li>
'comments_rss2_url'
(字符串):评论的 RSS 2.0 提要 URL。
<li>
'comments_atom_url'
(字符串):评论的 Atom 提要 URL。
<li>
'pingback_url'
(字符串):pingback XML-RPC 文件的 URL。
<li>
'stylesheet_url'
(字符串):主题主 CSS 文件的 URL。
<li>
'stylesheet_directory'
(字符串):主题主 CSS 文件目录的 URL。
<li>
'template_directory'
或 'template_url'
(字符串):活动主题目录的 URL。
<li>
'admin_email'
(字符串):安装WordPress时输入的电子邮件地址。
<li>
'charset'
(字符串):站点的字符集。
<li>
'html_type'
(字符串):WordPress HTML 页面的内容类型。
<li>
'version'
(字符串):WordPress 版本。
<li>
'language'
(字符串):WordPress 安装的语言。
<li>
'text_direction'
(字符串):语言的文本方向。
<li>
'name'
(字符串):站点名称。
$filter
(可选—字符串):将其设置为 'filter'
以过滤从此模板标记返回的 URL。
(默认:'原始')
而 bloginfo()
只接受一个参数:
-
<li>
$show
(可选—字符串):与上面相同的详细信息。
(默认:'blogname')
用法
<?php // Display the name of the site. bloginfo(); // Get the stylesheet url. $stylesheet = get_bloginfo( 'stylesheet_url' ); // Display the WordPress version. bloginfo( 'version' ); ?>
获取并显示自动 <body>
类:get_body_class()
& body_class()
这些非常流行的模板标签生成语义类并让我们回显或返回它们。他们还让我们添加额外的类名。
参数
两个模板标签只接受一个参数:
-
<li>
$class
(可选 - 字符串或数组):要添加的额外 CSS 类名称。
(默认:空) EM>
用法
<?php // Display the body class. body_class(); // Retrieve the body class with an extra class. $body_class = get_body_class( 'mytheme-body' ); ?>
获取并显示导航菜单:wp_nav_menu()
此模板标签返回或显示导航菜单,这是 WordPress 的核心功能。您可能会在 2013 年或以后发布的所有新 WordPress 主题中看到此模板标签。
参数
此模板标记仅接受一个参数:
-
<li>
$args
(可选—数组):以下参数的数组:
-
<li>
'menu'
(字符串):菜单的 ID、slug 或名称。(默认:空)
<li>
'menu_class'
(字符串):菜单的 UL
元素的 CSS 类。
(默认:'menu')
<li>
'menu_id'
(字符串):菜单的 UL
元素的 ID。
(默认:菜单slug,递增)
<li>
'container'
(string): 是否包裹UL
,以及用什么包裹它。
(默认:DIV
)
<li>
'container_class'
(字符串):包装元素的 CSS 类。
(默认:'menu-{menu slug}-container')
<li>
'container_id'
(字符串):包装元素的 ID。
(默认:空)
<li>
'fallback_cb'
(回调或布尔值):菜单不存在时运行的后备函数的名称。设置为 false 则不进行回退。
(默认:'wp_page_menu'
)
<li>
'before'
(字符串):链接文本之前的文本。
(默认:空)
<li>
'after'
(字符串):链接文本后的文本。
(默认:空)
<li>
'link_before'
(字符串):链接之前的文本。
(默认:空)
<li>
'link_after'
(字符串):链接后的文本。
(默认:空)
<li>
'echo'
(boolean): 是否回显模板标签。
(默认: TRUE
)
<li>
'depth'
(整数):要包含多少级层次结构。
(默认:0,表示所有级别)
<li>
'walker'
(对象):自定义 walker 类的实例。
(默认:空)
<li>
'theme_location'
(字符串):要使用的主题位置。必须使用 register_nav_menu() 注册才能被用户选择。
(默认:空)
<li>
'items_wrap'
(字符串):列表项应如何包装。
(默认:<ul id="%1$s" class="%2$s ">%3$s</ul>
)
用法
<?php $args = array( 'container_id' => 'primary-nav', 'link_before' => '<i class="icon-link"></i>', 'theme_location' => 'primary' ); wp_nav_menu( $args ); ?>
获取并显示页面标题:wp_title()
此模板标记返回或回显您页面的页面标题。
参数
此模板标记接受三个参数:
-
<li>
$sep
(可选 — 字符串):用作分隔符的文本。
(默认值:'»' )
<li>
$echo
(可选—布尔值):
是否回显(TRUE
)或返回(FALSE
)标签。
< em>(默认:TRUE
)
<li>
$seplocation
(可选—字符串):
分隔符的位置和面包屑的方向。将其设置为“right”以反转面包屑。
(默认:空)
用法
<?php wp_title( ' - ', true ); // Reverse the separator location to use left-hand indicators. $page_title = wp_title( ' « ', false, 'right' ); ?>
获取并显示主页 URL:get_home_url()
& home_url()
这些模板标签仅返回主页 URL。
参数
get_home_url()
接受三个参数:
-
<li>
$blog_id
(可选—整数):博客的 ID。
(默认:NULL
) >
<li>
$path
(可选—字符串):
附加到 URL 的可选路径。
(默认:空) >
<li>
$scheme
(可选—字符串):
提供主页 URL 上下文的方案(“http”、“https”或“相对”)。
(默认:NULL
)
并且 home_url()
接受两个参数:
-
<li>
$path
(可选—字符串):附加到 URL 的可选路径。
(默认:空) >
<li>
$scheme
(可选—字符串):
提供主页 URL 上下文的方案(“http”、“https”或“相对”)。
(默认:NULL
)
不要将这两个函数误认为“一个返回输出,另一个显示它”——我知道我就是这么做的。区别有点奇怪: get_home_url()
函数返回特定博客的主页 URL,而 home_url()
函数返回当前站点<的主页 URL /em>.请记住:它们都没有回应任何内容!
用法
<?php // Getting a specific blog's home url with https. $home_url_of_petes_blog = get_home_url( 2, '', 'https' ); // Echoes the current home url with a little addition. echo home_url( '?rel=navlink' ); ?>
获取并显示站点 URL:get_site_url()
& site_url()
这些模板标签获取并回显“站点 URL”,即安装 WordPress 的地址。
参数
get_site_url()
接受三个参数:
-
<li>
$blog_id
(可选 - 整数):博客的 ID。
(默认:当前站点)
<li>
$path
(可选—字符串):
附加到 URL 的可选路径。
(默认:空) >
<li>
$scheme
(可选—字符串):
提供主页 URL 上下文的方案(“http”、“https”或“相对”)。
(默认:正常或安全连接,取决于is_ssl()
)
并且 site_url()
接受两个参数:
-
<li>
$path
(可选—字符串):附加到 URL 的可选路径。
(默认:空) >
<li>
$scheme
(可选—字符串):
提供主页 URL 上下文的方案(“http”、“https”或“相对”)。
(默认:正常或安全连接,取决于is_ssl()
)
与 home_url()
和 get_home_url()
一样,不要将这两个函数误认为“一个返回输出,另一个显示输出”。 get_site_url()
函数返回特定博客的站点 URL,而 site_url()
函数返回当前站点的站点 URL。请记住:它们都没有回应任何内容!
用法
<?php // Getting a specific blog's site url with https. $site_url_of_janes_blog = get_site_url( 3, '', 'https' ); // Echoes the current site url. echo site_url(); ?>
获取当前站点的 ID:get_current_blog_id()
此模板标记仅返回多站点网络中当前站点的 ID。
参数
此模板标记不接受任何参数。
用法
<?php get_current_blog_id(); ?>
获取并显示管理面板的 URL:get_admin_url()
& admin_url()
这些模板标签返回并显示您网站仪表板的 URL。
参数
get_admin_url()
接受三个参数:
-
<li>
$blog_id
(可选 - 整数):博客的 ID。
(默认:当前站点)
<li>
$path
(可选—字符串):
附加到 URL 的可选路径。
(默认:空) >
<li>
$scheme
(可选 - 字符串):
要使用的方案。 “admin”遵循定义的方案(使用 is_ssl()
函数),但您可以通过设置此参数来覆盖它。接受“http”、“https”、“admin”、“rpc”、“login”和“login_post”。
(默认:“admin”)
并且 admin_url()
接受两个参数:
-
<li>
$path
(可选—字符串):附加到 URL 的可选路径。
(默认:空) >
<li>
$scheme
(可选 - 字符串):
要使用的方案。 “admin”遵循定义的方案(使用 is_ssl()
函数),但您可以通过将此参数设置为“http”或“https”来覆盖它。
(默认值:“管理员')
用法
<?php // Get the dashboard url of the current blog. $admin_url = get_admin_url(); // Display the admin url and force a secure connection. admin_url( '', 'https' ); ?>
获取并显示 Feed 类型的固定链接:get_feed_link()
& the_feed_link()
这些模板标记返回并输出提要的永久链接。
参数
get_feed_link()
只接受一个参数:
-
<li>
$feed_type
(可选 — 字符串):提要类型。
(默认:默认提要类型)
并且 the_feed_link()
接受两个参数:
-
<li>
$anchor
(必需 — 字符串):链接显示的文本。
(默认:NULL
) EM>
<li>
$feed_type
(可选 — 字符串):
提要类型。
(默认:默认提要类型)
用法
<?php // Get default feed type's link. get_feed_link(); // Display a link for the "atom" feed. the_feed_link( __( 'Atom Feed', 'translation-domain' ), 'atom' ); ?>
使字符串结尾有或没有尾部斜杠:user_trailingslashit()
此模板标记检查您的永久链接结构,并在给定 URL 末尾添加尾部斜杠或删除现有的尾部斜杠。
参数
此模板标记接受两个参数:
-
<li>
$string
(必需 — 字符串):带或不带尾部斜杠的 URL。
(默认:NULL
)
<li>
$type_of_url
(已弃用 - 字符串):
这在技术上并没有被弃用,但它没有在函数中使用,因此它没有任何效果。
用法
<?php $url_to_fix = user_trailingslashit( get_home_url() . 'some-special-page' ); ?>
获取自本周开始以来的天数:calendar_week_mod()
这个奇怪的模板标签获取自一周开始以来的天数。它基本上是一个“模运算”。
老实说,我不知道如何使用它或为什么使用它。如果您知道为什么存在此模板标签,请发表评论以告知我和我们的读者!
参数
此模板标记仅接受一个参数:
-
<li>
$number
(必需 - 整数):自本周开始以来的天数。
(默认值:0) >
用法
<?php // Umm... echo calendar_week_mod( 199 ); // Right? (it echoes "3" by the way). ?>
获取并显示日历:get_calendar()
还记得我们曾经放在博客侧边栏中的那些日历吗?此模板标记正是这样做的:它返回或显示日历。
参数
此模板标记接受两个参数:
-
<li>
$initial
(可选 - 布尔值):使用初始日历名称 (TRUE
) 或不使用 (FALSE
)。
(默认:TRUE
)
<li>
$echo
(可选—布尔值):
是否回显(TRUE
)或返回(FALSE
)输出。
< em>(默认:TRUE
)
用法
<?php // Return the calendar. $my_calendar = get_calendar( true, false ); // Display the calendar. get_calendar(); ?>
结论
希望您喜欢最后一批模板标签。在下一部分,即系列结局中,我们将回顾我们所学到的内容并结束该系列。
如果您有任何问题、意见或更正,您可以在评论部分与我们分享您的想法。如果您喜欢这篇文章,请不要忘记与您的朋友分享!
The above is the detailed content of Tuts+ Guide to the Eighth Batch of Template Tags. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



With the launch of Windows 11, Microsoft has introduced some new features and updates, including a security feature called VBS (Virtualization-basedSecurity). VBS utilizes virtualization technology to protect the operating system and sensitive data, thereby improving system security. However, for some users, VBS is not a necessary feature and may even affect system performance. Therefore, this article will introduce how to turn off VBS in Windows 11 to help

VSCode Setup in Chinese: A Complete Guide In software development, Visual Studio Code (VSCode for short) is a commonly used integrated development environment. For developers who use Chinese, setting VSCode to the Chinese interface can improve work efficiency. This article will provide you with a complete guide, detailing how to set VSCode to a Chinese interface and providing specific code examples. Step 1: Download and install the language pack. After opening VSCode, click on the left

Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

With the continuous development of technology, Linux operating systems have been widely used in various fields. Installing Deepin Linux system on tablets allows us to experience the charm of Linux more conveniently. Let’s discuss the installation of Deepin Linux on tablets. Specific steps for Linux. Preparation work Before installing Deepin Linux on the tablet, we need to make some preparations. We need to back up important data in the tablet to avoid data loss during the installation process. We need to download the image file of Deepin Linux and write it to to a USB flash drive or SD card for use during the installation process. Next, we can start the installation process. We need to set the tablet to start from the U disk or SD

Conda Usage Guide: Easily upgrade the Python version, specific code examples are required Introduction: During the development process of Python, we often need to upgrade the Python version to obtain new features or fix known bugs. However, manually upgrading the Python version can be troublesome, especially when our projects and dependent packages are relatively complex. Fortunately, Conda, as an excellent package manager and environment management tool, can help us easily upgrade the Python version. This article will introduce how to use

A practical guide to solving Tomcat garbled characters Introduction: In web development, we often encounter the problem of Tomcat garbled characters. Garbled characters may cause users to be unable to display or process data correctly, causing inconvenience to the user experience. Therefore, solving the Tomcat garbled problem is a very important step. This article will provide you with some practical guidelines to solve Tomcat garbled code, and attach specific code examples to help you easily deal with this problem. 1. Understand the causes of Tomcat garbled characters. The main cause of Tomcat garbled characters is characters.

PHP7 Installation Directory Configuration Guide PHP is a popular server-side scripting language used to develop dynamic web pages. Currently, the latest version of PHP is PHP7, which introduces many new features and performance optimizations and is the preferred version for many websites and applications. When installing PHP7, it is very important to correctly configure the installation directory. This article will provide you with a detailed guide to configuring the PHP7 installation directory, with specific code examples. To download PHP7 first, you need to download it from the PHP official website (https://www.

Golang Desktop Application Development Guide With the popularity of the Internet and the advent of the digital age, desktop applications are playing an increasingly important role in our lives and work. As a powerful programming language, Golang (Go language) is gradually emerging in the field of desktop application development. This article will introduce you to how to use Golang to develop desktop applications and provide specific code examples to help you get started quickly and master development skills. First, we need to understand some basic concepts and tools. In Gol
