零基础建站培训介绍

当前位置:

WordPress bloginfo()函数语法与详细使用方法

bloginfo() 直接在浏览器中输出内容,我们创建一个wordpress博客的时候,我们需要填写博客的相关信息,包括博客名称,博客描述,博客地址等等。当我们需要使用这些信息的时候,就可以使用bloginfo()函数来获取wordpress博客的相关信息。

语法结构


<?php bloginfo( $show ); ?>

参数:

  • $show (字符串string) (可选)你需要输出的信息的关键词。 默认值: name
  • ‘name’:显示在 设置 -> 常规 中设置的“站点标题”。该数据是从 wp_options 这个数据表中检索到的 “blogname”记录。
  • ‘description’:显示在 设置 -> 常规 中设置的“副标题”。该数据是从 wp_options 这个数据表中检索到的 “blogdescription” 记录。
  • ‘admin_email’:显示在 设置 > 常规 中设置的 “电子邮件地址”。该数据是从 wp_options 这个数据表中检索到的 “admin_email”记录。
  • ‘charset’:显示在 设置 > 常规 中设置的“页面和feed的编码”。该数据是从 wp_options 这个数据表中检索到的”blog_charset” 记录。(注:3.5.1+好像已经没有这个选项了)
  • ‘html_type’:显示WordPress HTML 页面中的内容类型(默认: “text/html”)。该数据可以从 wp_options 这个数据表中检索到的
  • “html_type” 记录。主题和插件可以通过使用 pre_option_html_type 过滤器覆盖默认值。
  • ‘language’:显示WordPress的语言。
  • ‘wpurl’:显示在 设置 > 常规 中设置的 “WordPress 地址 (URL)”。该数据是从 wp_options 这个数据表中检索到的 “siteurl” 记录。 可以考虑使用 site_url() 来代替,尤其是在使用 子目录路径方式,而不是使用 子域名 来配置多站点时(bloginfo将返回根网站的URL,而不是子站点的URL)。
  • ‘url’:显示在 设置 > 常规 中设置的 “站点地址(URL)”。该数据是从 wp_options 这个数据表中检索到的 “home”记录。 可以考虑使用 home_url() 代替。
  • ‘stylesheet_url’:显示当前使用的主题的 CSS文件(通常为 style.css)路径。可以考虑使用 get_stylesheet_uri() 代替。
  • ‘template_url’/’template_directory’:当前主题的 URL 路径 。在子主题中, get_bloginfo(‘template_url’) 和 get_template() 都将返回父主题的目录。可以考虑使用 get_template_directory_uri() (用于父主题目录)或get_stylesheet_directory_uri() (用于子主题目录)代替。
  • ‘stylesheet_directory’:显示当前使用的主题的样式表路径。可以考虑使用 get_stylesheet_directory_uri() 代替。

示例输出

  • name = 获得更好的笔记查询体验
  • description = 又一个WordPress站点
  • admin_email = admin@example.com
  • charset = UTF-8
  • html_type = text/html
  • language = en-US
  • wpurl = http://www.xuewangzhan.net/content/themes/XXX/(获得安装路径)
  • url = http://www.xuewangzhan.net/(获得首页地址)
  • stylesheet_url = http://www.example.com/home/wp/wp-content/themes/bluesky/style.css
  • stylesheet_directory = http://www.example.com/home/wp/wp-content/themes/bluesky
  • template_directory = http://www.example.com/home/wp/wp-content/themes/bluesky
  • template_url = http://www.example.com/home/wp/wp-content/themes/bluesky
  • text_direction = ltr
  • version = 3.5
  • home = http://www.example.com/home (已弃用!使用 url 替代)
  • siteurl = http://www.example.com/home (已弃用!使用 url 替代)
上一课: 下一课:

发表评论

邮箱地址不会被公开。 必填项已用*标注

相关教程