摘自的源代码get_bloginfo()
, 这是一个非常简单的类,您可以根据自己的意愿使用和扩展它。
我决定使用方法,从类中公开属性确实不是很好的编码,也不推荐使用。我知道Wordpress是靠公共财产发展起来的,但那就是Wordpress。
下面是一个类(,您应该将其转换为使用适当的名称空间,正如我所说的,这是一个非常简单的类)
class GetBlogInfo
{
// Return the home URL
public function homeURL()
{
return home_url();
}
// Return the site URL
public function siteURL()
{
return site_url();
}
// Return the blog description
public function description()
{
return get_option(\'blogdescription\');
}
// Get the feed links
public function getFeedLink( $link = \'\' )
{
switch( $link ) {
case \'rdf_url\':
$output = \'rdf\';
break;
case \'rss_url\':
$output = \'rss\';
break;
case \'rss2_url\':
$output = \'rss2\';
break;
case \'atom_url\':
$output = \'atom\';
break;
case \'comments_atom_url\':
$output = \'comments_atom\';
break;
case \'comments_rss2_url\':
$output = \'comments_rss2\';
break;
default:
$output = false;
break;
}
if ( $output ) {
return get_feed_link( $output );
} else {
return false;
}
}
// Return the blog options. Default is name
public function getOptions( $option = \'name\' )
{
switch( $option ) {
case \'admin_email\':
$output = \'admin_email\';
break;
case \'charset\':
$output = \'blog_charset\';
break;
case \'html_type\':
$output = \'html_type\';
break;
case \'name\':
default:
$output = \'blogname\';
break;
}
return get_option( $output );
}
// Return the blog language setting
public function language()
{
return str_replace( \'_\', \'-\', get_locale() );
}
// Return the Wordpress version
public function version()
{
global $wp_version;
return $wp_version;
}
// Return the pingback URL
public function pingbackURL()
{
return site_url( \'xmlrpc.php\' );
}
// Return the path to main stylesheet
public function stylesheetURL()
{
return get_stylesheet_uri();
}
// Return the stylesheet directory uri
public function stylesheetDirectory()
{
return get_stylesheet_directory_uri();
}
// Return the template directory uri
public function templateDirectory()
{
return get_template_directory_uri();
}
}
您可以按如下方式使用该类:
$q = new GetBlogInfo();
echo $q->homeURL() . \'</br>\';
echo $q->siteURL() . \'</br>\';
echo $q->description() . \'</br>\';
echo $q->getFeedLink( \'rdf_url\' ) . \'</br>\';
echo $q->getFeedLink( \'rss_url\' ) . \'</br>\';
echo $q->getFeedLink( \'rss2_url\' ) . \'</br>\';
echo $q->getFeedLink( \'atom_url\' ) . \'</br>\';
echo $q->getFeedLink( \'comments_atom_url\' ) . \'</br>\';
echo $q->getFeedLink( \'comments_rss2_url\' ) . \'</br>\';
echo $q->getOptions( \'name\' ) . \'</br>\';
echo $q->getOptions( \'admin_email\' ) . \'</br>\';
echo $q->getOptions( \'charset\' ) . \'</br>\';
echo $q->getOptions( \'html_type\' ) . \'</br>\';
echo $q->language() . \'</br>\';
echo $q->version() . \'</br>\';
echo $q->pingbackURL() . \'</br>\';
echo $q->stylesheetURL() . \'</br>\';
echo $q->stylesheetDirectory() . \'</br>\';
echo $q->templateDirectory() . \'</br>\';
此输出在我的测试安装中测试如下
http://localhost/wordpress
http://localhost/wordpress
Trots Afrikaans - Praat Afrikaans of hou jou bek!!!
http://localhost/wordpress/feed/rdf/
http://localhost/wordpress/feed/rss/
http://localhost/wordpress/feed/
http://localhost/wordpress/feed/atom/
http://localhost/wordpress/comments/feed/atom/
http://localhost/wordpress/comments/feed/
Pieter Goosen
[email protected]
UTF-8
text/html
af-AF
4.3.1
http://localhost/wordpress/xmlrpc.php
http://localhost/wordpress/wp-content/themes/pietergoosen2014/style.css
http://localhost/wordpress/wp-content/themes/pietergoosen2014
http://localhost/wordpress/wp-content/themes/pietergoosen2014