wordpress核心、主题或插件包含一些可设置的选项,保存在 wordpress数据库的wp_options表。 可以使用get_option()函数读取wordpress数据库的值。
注意,以前wordpress中的get_settings()函数,就是被现在的get_option()函数取代了。
语法:
get_option( string $option, mixed $default = false )
参数:
- $option:(string) (Required) 可选项名
- $default:(mixed) (Optional) 如果可选性不存在返回的默认值
- 返回:(mixed) 可选项值
举例:
<?php echo get_option(“blog_charset“); ?> //得到你的blog的字符集
<?php $admin_email = get_option(‘admin_email’); ?> //得到你的blog的email
举例:
<?php $options=get_option('options'); ?>
说明:$options 全局变量
举例:
if ( 'posts' == get_option( 'show_on_front' ) )
{ include( get_home_template() ); }
补充: 如下是一些常用的可选项。更多的请参考 Option Reference.
https://codex.wordpress.org/Option_Reference
‘admin_email’ – E-mail address of blog administrator.
‘blogname’ – Weblog title; set in General Options.
‘blogdescription’ – Tagline for your blog; set in General Options.
‘blog_charset’ – Character encoding for your blog; set in Reading Options.
‘date_format’ – Default date format; set in General Options.
‘default_category’ – Default post category; set in Writing Options.
‘home’ – The blog’s home web address; set in General Options.
‘siteurl’ – WordPress web address; set in General Options.
Warning: This is not the same as get_bloginfo( ‘url’ ) (which will return the homepage url), but as get_bloginfo( ‘wpurl’ ).
‘template’ – The current theme’s name; set in Presentation.
‘start_of_week’ – Day of week calendar should start on; set in General Options.
‘upload_path’ – Default upload location; set in Miscellaneous Options.
‘users_can_register’ – Whether users can register; set in General Options.
‘posts_per_page’ – Maximum number of posts to show on a page; set in Reading Options.
‘posts_per_rss’ – Maximum number of most recent posts to show in the syndication feed; set in Reading Options.
There are many more options available, a lot of which depend on what plugins you have installed.