WordPress获取文章内容函数:get_the_content

WordPress函数get_the_content用于获取文章内容,通常用在主循环The Loop中。 get_the_content( string $more_link_text = null, bool $strip_teaser = false, WP_Post|object|int $post = null ) 函数参数$more_link_text 字符串,默认值:null 当文章使用More标签分隔摘要内容时,get_the_content()函数只返回摘要内容。如果还有更多内容未能显示,将输出一个“更多”按钮,可以提供一个文本值来替换默认的更多按钮文本。 …

WordPress获取当前Post ID函数:get_the_ID

WordPress函数get_the_ID一般用在主循环The Loop中,以获取当前Post ID。也可以在文章模板、页面模板中使用,在这些页面即使主循环之外也能获取到当前页面的ID。 get_the_ID() 函数使用示例<?php $id = get_the_ID(); $dropdown = "<select name='dropdown-".$id."' >"; $dropdown .= "<option id='option-" . $id ."'>Option</option>"; $dropdown .= "</select>"; ?> 扩展阅读get_the_ID()函数位于:wp-includes/post-template.php …

WordPress添加元数据设置项函数:add_meta_box

WordPress添加元数据设置项函数:add_meta_box

WordPress函数add_meta_box用于为指定文章类型添加元数据设置项,例如可以为文章添加一个关键词设置单元。 add_meta_box( string $id, string $title, callable $callback, string|array|WP_Screen $screen = null, string $context = 'advanced', string $priority = 'default', array $callback_args = null ) 函数参数$id 字符串 …

WordPress生成摘要函数:wp_trim_excerpt

WordPress函数wp_trim_excerpt生成长度为55字符的文章摘要。 wp_trim_excerpt( string $text = '', WP_Post|object|int $post = null ) 函数参数$text 字符串 摘要文字,如果为空,则从文章内容中提取。 $post 整数或WP_Post对象 …

WordPress为文章添加分类法函数:wp_set_post_terms

WordPress函数wp_set_post_terms为指定文章添加分类法。 wp_set_post_terms( int $post_id, string|array $tags = '', string $taxonomy = 'post_tag', bool $append = false ) 函数参数$post_id 整数,文章的ID $tags 字符串或数组 分类/标签的名称 $taxonomy 字符串,默认值:post_tag …

WordPress获取文章所属分类法函数:wp_get_post_terms

WordPress函数wp_get_post_terms可用于获取指定文章所属的分类法。 wp_get_post_terms( int $post_id, string|string[] $taxonomy = 'post_tag', array $args = array() ) 函数参数$post_id 整数 文章的ID $taxonomy 字符串,默认值:post_tag 分类法名称,默认为标签。可选值:category …

WordPress设置文章标签函数:wp_set_post_tags

WordPress函数wp_set_post_tags用于给文章分配标签。 wp_set_post_tags( int $post_id, string|array $tags = '', bool $append = false ) 函数参数$post_id 整数 文章的ID $tags 字符串或数组 要分配的标签名称,分配多个标签时,使用一个包含各标签名称的数组。 …

WordPress获取文章所属标签对象函数:wp_get_post_tags

WordPress函数wp_get_post_tags根据文章ID获取该文章的标签对象,返回数据中包含了标签的ID、名称、别名等信息。 wp_get_post_tags( int $post_id, array $args = array() ) 函数参数$post_id 整数 文章的ID …

WordPress设置文章分类函数:wp_set_post_categories

WordPress函数wp_set_post_categories用于为指定文章设置分类,默认情况下,新设置的分类将替换旧设置,如果要修改这一默认行为,可以设置$append的值为true。 …

WordPress根据文章ID获取文章所在分类函数:wp_get_post_categories

WordPress函数wp_get_post_categories根据文章的ID获取该文章所在分类,如果文章分配了多个分类,则返回所有分类的ID。 wp_get_post_categories( int $post_id, array $args = array() ) 函数参数$post_id …