100个常用WordPress函数

WordPress 开发1 1.5K阅读模式

WordPress 是一个功能强大的平台,数百种核心函数,很难都记住,这里分享一些最常见的WordPress函数,供查询参考。

1.get_theme_mod()

检索当前主题的主题修改值。


2. add_setting()

添加自定义设置。


4.apply_filters()

调用添加到过滤器挂钩的函数。


5. esc_attr()

转义 HTML 属性。


6.get_option()

根据选项名称检索选项值。


7. esc_url()

检查并清理 URL。


8. esc_html()

转义 HTML 块。


9 和()

在 WordPress 中,php 文件中的字符串被标记为翻译成其他语言,并使用两个函数进行本地化:__() 和 _e()。


10.苦艾酒()

将值转换为非负整数。


11. 获取模板部分()

将模板部件加载到模板中。


12. is_singular()

是否查询任何帖子类型(帖子、附件、页面、自定义帖子类型)的现有单个帖子?


13.get_post_type()

检索当前帖子或给定帖子的帖子类型。


14. 获取_the_ID()

检索 WordPress 循环中当前项目的 ID。


15.the_content()

显示帖子内容。


16. 有_posts()

当前的 WordPress 查询是否有结果要循环。


17. post_class()

显示帖子 div 的类。


18. 获取评论号码()

检索帖子的评论数量。


19. the_ID()

显示 WordPress 循环中当前项目的 ID。


20. is_single()

是对现有单个帖子的查询吗?


21.get_permalink()

检索当前帖子或帖子 ID 的完整永久链接。


22. get_the_title()

检索帖子标题。


23. admin_url()

检索当前站点管理区域的 URL。


24.add_section()

添加自定义部分。


25.is_home()

确定查询是否针对博客主页。


26.get_sidebar()

加载侧边栏模板。


27.get_footer()

加载页脚模板。


28. is_customize_preview()

是否正在定制器中预览站点。


29. wp_nav_menu()

显示导航菜单。


30.the_title()

使用可选标记显示或检索当前帖子标题。


31. current_user_can()

当前用户是否具有特定的能力。


32. is_active_sidebar()

侧边栏是否正在使用。


33. wp_link_pages()

页面列表的格式化输出。


34.get_the_time()

检索撰写帖子的时间。


35. get_the_date()

Retrieve the date on which the post was written.


36. the_permalink()

Displays the permalink for the current post.


37. the_post()

Iterate the post index in the loop.


38. esc_attr_e()

Display translated text that has been escaped for safe use in an attribute.


39. is_front_page()

Is the query for the front page of the site?


40. bloginfo()

Displays information about the current site.


41. comments_open()

Whether the current post is open for comments.


42. post_password_required()

Whether post requires password and correct password has been provided.


43. has_post_thumbnail()

Check if post has an image attached.


44. 获取博客信息()

检索有关当前站点的信息。


45.get_post_format()

检索帖子的格式 slug


46.动态侧边栏()

显示动态侧边栏。


47.is_search()

查询是搜索吗?


48.home_url()

检索可访问前端的当前站点的 URL。


49.comments_template()

加载 $file 中指定的注释模板。


50. add_theme_support()

注册给定功能的主题支持。


51. add_query_arg()

检索修改后的 URL 查询字符串。


52. has_nav_menu()

Determines whether a registered nav menu location has a menu assigned to it.


53. is_wp_error()

Check whether variable is a WordPress Error.


54. get_the_author_meta()

Retrieves the requested data of the author of the current post.


55. edit_post_link()

Displays the edit post link for post.


56. is_admin()

Whether the current request is for an administrative interface page.


57. the_excerpt()

Display the post excerpt.


58. wp_get_attachment_image_src()

Retrieve an image to represent an attachment.


59. _x()

Retrieve translated string with gettext context.


60. language_attributes()

Displays the language attributes for the html tag.


61. body_class()

Display the classes for the body element.


62. add_filter()

Hook a function or method to a specific filter action.


63. is_page()

Is the query for an existing single page?


64. register_sidebar()

Builds the definition for a single sidebar and returns the ID.


65. get_the_category_list()

Retrieve category list for a post in either HTML list or custom format.


66. get_the_tag_list()

Retrieve the tags for a post formatted as a string.


67. esc_attr_x()

Translate string with gettext context, and escapes it for safe use in an attribute.


68. get_setting()

Get value based on option. (Use get_option() instead.)


69. add_action()

将函数与特定操作挂钩。


70. 有评论()

是否有评论要循环。


71.is_archive()

是对现有存档页面的查询吗?


72. wp_list_comments()

列出评论。


73. wp_enqueue_style()

Enqueue a CSS stylesheet.


74. set_transient()

Set/update the value of a transient.


75. wp_enqueue_script()

Enqueue a script.


76. get_search_form()

Display search form.


77. get_post_thumbnail_id()

Retrieve post thumbnail ID.


78.get_transient()

获取瞬态的值。


79. the_post_thumbnail()

显示帖子缩略图。


80.get_search_query()

检索搜索 WordPress 查询变量的内容。


81. add_partial()


82.get_the_modified_date()

Retrieve the date on which the post was last modified.


83. get_author_posts_url()

Retrieve the URL to the author page for the user with the ID provided.


84. wp_footer()

Fire the wp_footer action.


85. wp_head()

Fire the wp_head action.


86. get_the_post_thumbnail()

Retrieve the post thumbnail.


87. comment_form()

Outputs a complete commenting form for use within a template.


88. number_format_i18n()

Convert float number to format based on the locale.


89.get_header()

加载标题模板。


90.the_posts_pagination()

显示分页导航到下一组/上一组帖子(如果适用)。


91. register_nav_menus()

注册主题的导航菜单位置。


92. wp_die()

终止 WordPress 执行并显示带有错误消息的 HTML 消息。


93. wp_reset_postdata()

在循环一个单独的查询之后,这个函数将 $post 全局恢复到主查询中的当前帖子。


94. 加载主题文本域()

加载主题的翻译字符串。


95.get_queried_object_id()

检索当前查询对象的 ID。


96. esc_url_raw()

为数据库使用执行 esc_url()。


97.the_archive_title()

根据查询的对象显示归档标题。


98. add_image_size()

注册新的图像尺寸。


99.get_theme_file_uri()

检索主题中文件的 URL。


100.get_stylesheet_uri()

检索当前主题样式表的 URI。

本站文章大部分始于原创,用于个人学习记录,可能对您有所帮助,仅供参考!

weinxin
我的微信
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
 
知更鸟
    • 谷歌优化
      谷歌优化 2

      回去好好研究一下,感谢分享

    匿名

    发表评论

    匿名网友
    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

    拖动滑块以完成验证