WordPress函数:get_option

WordPress后台有一些可视化的设置选项,这些选项都可以通过get_option函数来调用,小雨今天来说说get_option函数的使用方法:

get_option( string $option, mixed $default = false )

Retrieves an option value based on an option name.

得到的类型取决于设置参数本身的类型。

参数:

$option

(string) (Required) Name of option to retrieve. Expected to not be SQL-escaped.

 $default

(mixed) (Optional) Default value to return if the option does not exist.

Default value: false

用中文来说就是前面一个参数是参数的名称,后面一个是没有设置参数值时候的默认值。(终于知道大学为啥要过英语四级了。。。,感觉好有用!)

 

A concise list of commonly-used options is below。

下面举出一些wordpress后台常用的设置选项

  • '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.

函数用法举例:

<?php echo get_option('posts_per_page', 20);?>

函数返回你后台设置的每页显示多少篇文章,没有设置的话,就默认20篇。

AD:站点文章对你有帮助,可以选择去百度口碑好评下,还可以点击此处

赞 (1) 口碑
分享到:更多 ()

评论 0

评论前请先注册,游客请前往问答中心