WordPress判断文章页面函数:is_single

WordPress函数is_single用于判断是否文章类型为post的页面,但不包括附件(attachments)和页面(page)。换句话说,is_single()函数判断当前页面是否是文章页面,如果要包含附件和页面,请使用is_singular()函数。 …

WordPress获取上一篇文章函数:get_previous_post

WordPress函数get_previous_post用于获取上一篇文章,可以限制返回相同分类的上一篇文章,需要用在文章页面模板里。 get_previous_post( boolean $in_same_cat, string $excluded_categories ) 函数参数$in_same_cat 布尔值,默认值:false …

WordPress获取删除文章链接函数:get_delete_post_link

WordPress函数get_delete_post_link获取删除文章的链接,访问获取到的这个链接将会把这篇文章移至回收站。该函数可以用于The Loop主循环或主循环之外。 get_delete_post_link( integer $id, string $deprecated, bool $force_delete ) 函数参数$id …

WordPress获取编辑文章链接函数:get_edit_post_link

WordPress函数get_edit_post_link用于获取文章的编辑链接,需要用户登录网站后台才能获取到编辑文章的链接,如果未登录状态则不返回任何内容。 get_edit_post_link( integer $id, string $context ) 函数参数$id …

WordPress支持WebP格式图片上传方法

之前我写过一篇压缩图片的文章——PhotoShop高度压缩图片技巧,虽然这种方式已经可以大幅度压缩图片体积,但WebP格式的图片相较于这种方式图片体积还要小2倍! 在浏览器支持方面,现在主流的浏览器也都支持WebP格式,况且像微信公众号这样的大平台早已开始使用WebP图片,因此没有理由不将博客的插图换成WebP了。 …

WordPress获取文章形式函数:get_post_format

WordPress函数get_post_format用于获取文章的形式,在为不同形式的文章制作不同的模板时非常有用。 get_post_format( int $post = null ) 函数参数$post_id 整数型,默认值:null 文章的ID 函数返回值 aside 日志 chat 聊天 gallery 相册 link 链接 image 图像 quote 引语 status 状态 video 视频 audio 音频 标准形式的文章不会返回任何值。 …

WordPress获取文章状态函数:get_post_status

WordPress函数get_post_status用于获取文章的状态,比较少用到。 get_post_status( int $ID ) 函数参数$ID 整数型,默认为空 文章的ID 函数返回值 publish:公开的; pending:待审核; draft:草稿; auto-draft:自动草稿; future:定时; private:私有的; inherit:继承,子页面继承父级页面属性; trash:垃圾箱; 函数使用示例<?php if ( get_post_status ( 28 ) == 'private' ) { echo 'private'; } else { echo 'public'; } ?> 扩展阅读get_post_status()函数位于:wp-includes/post.php …

WordPress获取附件MIME类型函数:get_post_mime_type

WordPress函数get_post_mime_type主要用于获取附件的MIME类型,当然也能返回文章、页面的MIME类型,但在实际应用中这并没有什么用处。 get_post_mime_type( int $ID ) 函数参数$ID 整数型,默认为空 …

WordPress获取父页面ID函数:get_post_ancestors

WordPress函数get_post_ancestors用于获取父页面的ID,通常在企业模板中,侧边栏需要显示页面导航,例如:公司简介、企业文化、人才招聘等等,就可能需要用get_post_ancestors函数来获取父页面。 …

WordPress获取文章数据函数:get_post

WordPress函数get_post用于获取文章的数据,包括文章内容、标题、别名、摘要、发布时间等信息。 get_post( int $post = null, string $output = OBJECT, string $filter = 'raw' ) 函数参数$post 整数型,默认值:null 文章的ID,或对象 …