WordPress的bloginfo(), get_bloginfo()函数详解

最近到Wordpress很感兴趣,想做一个属于自己的主题
现在在研究bloginfo, get_bloginfo函数
在官网找到的帮助,其实用的参数也很少。

参数如下:

name = Testpilot
description = Just another WordPress blog
admin_email = admin@example

url = http://example/home
wpurl = http://example/home/wp

stylesheet_directory = http://example/home/wp/wp-content/themes/child-theme
stylesheet_url = http://example/home/wp/wp-content/themes/child-theme/style.css
template_directory = http://example/home/wp/wp-content/themes/parent-theme
template_url = http://example/home/wp/wp-content/themes/parent-theme

atom_url = http://example/home/feed/atom
rss2_url = http://example/home/feed
rss_url = http://example/home/feed/rss
pingback_url = http://example/home/wp/xmlrpc.php
rdf_url = http://example/home/feed/rdf

comments_atom_url = http://example/home/comments/feed/atom
comments_rss2_url = http://example/home/comments/feed

charset = UTF-8
html_type = text/html
language = en-US
text_direction = ltr
version = 2.9.2

使用的时候,就比较简单了

<?php "Your blog charset is: ".bloginfo('charset'); ?>
 
//结果是:
Your blog charset is: UTF-8

bloginfo()函数在/wordpress/wp-includes/general-template.php定义

bloginfo()

function bloginfo($show='') {
	echo get_bloginfo($show, 'display'); //这里调用了get_bloginfo()
}

get_bloginfo()

//这个函数基本上是调用了数据库中wp-options表中的数据
function get_bloginfo($show = '', $filter = 'raw') {
 
	switch($show) {
		case 'url' :
		case 'home' : // DEPRECATED
		case 'siteurl' : // DEPRECATED
			$output = get_option('home');
			break;
		case 'wpurl' :
			$output = get_option('siteurl');
			break;
		case 'description':
			$output = get_option('blogdescription');
			break;
		case 'rdf_url':
			$output = get_feed_link('rdf');
			break;
		case 'rss_url':
			$output = get_feed_link('rss');
			break;
		case 'rss2_url':
			$output = get_feed_link('rss2');
			break;
		case 'atom_url':
			$output = get_feed_link('atom');
			break;
		case 'comments_atom_url':
			$output = get_feed_link('comments_atom');
			break;
		case 'comments_rss2_url':
			$output = get_feed_link('comments_rss2');
			break;
		case 'pingback_url':
			$output = get_option('siteurl') .'/xmlrpc.php';
			break;
		case 'stylesheet_url':
			$output = get_stylesheet_uri();
			break;
		case 'stylesheet_directory':
			$output = get_stylesheet_directory_uri();
			break;
		case 'template_directory':
		case 'template_url':
			$output = get_template_directory_uri();
			break;
		case 'admin_email':
			$output = get_option('admin_email');
			break;
		case 'charset':
			$output = get_option('blog_charset');
			if ('' == $output) $output = 'UTF-8';
			break;
		case 'html_type' :
			$output = get_option('html_type');
			break;
		case 'version':
			global $wp_version;
			$output = $wp_version;
			break;
		case 'language':
			$output = get_locale();
			$output = str_replace('_', '-', $output);
			break;
		case 'text_direction':
			global $wp_locale;
			$output = $wp_locale-&gt;text_direction;
			break;
		case 'name':
		default:
			$output = get_option('blogname');
			break;
	}
 
	$url = true;
	if (strpos($show, 'url') === false &amp;&amp;
		strpos($show, 'directory') === false &amp;&amp;
		strpos($show, 'home') === false)
		$url = false;
 
	if ( 'display' == $filter ) {
		if ( $url )
			$output = apply_filters('bloginfo_url', $output, $show);
		else
			$output = apply_filters('bloginfo', $output, $show);
	}
 
	return $output;
}