WordPress企业主题定制/开发/优化

WP get_bloginfo参数及用法

首页 » WORDPRESS主题技术 » WP get_bloginfo参数及用法

说明
该函数返回用户博客的相关信息,可将返回的信息用在PHP代码中。该函数与bloginfo()均可以显示博客相关信息。

用法
<?php $bloginfo = get_bloginfo( $show ); ?>

参数
$show
(字符串)(可选)可命名你所需要的信息的关键字。
默认值:name
忽略$show参数,或者传递的值不在下面列出的范围内,get_bloginfo返回博客标题。

name
(默认)返回管理面板>设置>常规中设定的博客标题。可从wp_option数据库表的blogname记录中获取name信息。

description

管理面板>设置>常规中设定的博客说明/标语。可从wp_option数据库表的blogdescription记录中获取name信息。

url
博客地址(URI),即博客网站URL,在管理面板>设置>常规中设定。可从wp_option数据库表的home记录中获取该url信息。

wpurl
WordPress地址,即你的WordPress安装地址,在管理面板>设置>常规中设定。可从wp_option数据库表的siteurl记录中获取该信息。

rdf_url
博客 RDF/RSS 1.0订阅URL (/feed/rfd)。

rss_url
博客RSS 0.92 订阅URL (/feed/rss)

rss2_url
博客RSS 2.0 订阅URL (/feed)

atom_url
博客 Atom订阅URl(/feed/atom)

comments_rss2_url
博客评论 RSS 2.0订阅URL(/comments/feed)

pingback_url
pingback XML-RPC文件的URL(xmlrpc.php)

stylesheet_url
当前主题主CSS文件(通常为style.css)的URL

stylesheet_directory
当前主题样式表文件夹的URL。(WordPress早期时为本地路径)

template_directory
template_url
当前主题目录的URL。(在WP 2.6之前,template_directory为本地路径;其它用法请见get_theme_root() 与 get_template()。)

admin_email
在管理面板>设置>常规中设定的博客管理者的E-mail地址。可从wp_option数据库表的admin_email记录中获取该信息。

charset
在管理面板>设置>常规中设定的页面和feeds的编码方式。可从wp_option数据库表的blog_charset记录中获取该信息。

version
当前使用的WordPress版本信息。该信息即wp-includes/version.php中设定的 $wp_version变量的值。

html_type
WordPress的HTML页面的文本类型(默认:text/html);存储在wp_option数据库表的html_type记录中。主题和插件都可以通过 pre_option_html_type过滤器改写html_type的默认值(参见插件API/常用过滤器(filter))。
示例

默认用法
默认用法将博客标题赋予变量$blog_title
<?php $blog_title = get_bloginfo(); ?>

博客标题
将博客标题赋值给变量$blog_title,返回的值与默认用法相同
<?php $blog_title = get_bloginfo('name'); ?>

博客标语

使用以下代码:

<?php echo 'Your Blog Tagline is: ' . get_bloginfo ( 'description' );  ?><br />

使博客上显示:

Your Blog Tagline is: All things WordPress

示例输出

在WP 2.7中,假设example为博客名,博客地址为 http://example/home,WordPress安装地址为 http://example/home/wp。

注意其中的目录URL没有结尾斜线。

admin_email = admin@example
atom_url = http://example/home/feed/atom
charset = UTF-8
comments_atom_url = http://example/home/comments/feed/atom
comments_rss2_url = http://example/home/comments/feed
description = Just another WordPress blog
home = http://example/home
html_type = text/html
language = en-US
name = Testpilot
pingback_url = http://example/home/wp/xmlrpc.php
rdf_url = http://example/home/feed/rdf
rss2_url = http://example/home/feed
rss_url = http://example/home/feed/rss
siteurl = http://example/home
stylesheet_directory = http://example/home/wp/wp-content/themes/largo
stylesheet_url = http://example/home/wp/wp-content/themes/largo/style.css
template_directory = http://example/home/wp/wp-content/themes/largo
template_url = http://example/home/wp/wp-content/themes/largo
text_direction = ltr
url = http://example/home
version = 2.7
wpurl = http://example/home/wp

原文:http://www.wordpress.la/codex-%E6%A8%A1%E6%9D%BF%E6%A0%87%E7%AD%BE-get_bloginfo%28%29.html

相关项目

  • WordPress外贸企业主题

  • 最近更新

  • 热门标签