正确理解Wordpress设置API

Wordpress设置API使用起来并不算太方便,很多地方都容易混淆,因此在本人读懂并改写了主题相关的设置类之后,就想把相关容易混淆的地方详细说明一下。

函数register_settingsettings_fields为一组,它们之间使用参数option_group进行关联,另外函数register_setting注册了get_option函数所需要的参数option_name。这两个函数一个用于注册设置信息,一个用于显示设置信息(实际即一组hidden属性的input标签,显示时使用参数option_group)。

函数add_settings_sectionadd_settings_fieldadd_[theme或options]_page为一组,它们之间使用参数menu_slug进行关联,由该参数可知这些函数只与某个特别的page相关,用于注册表单展示信息。使用函数do_settings_sections来渲染展示表单(显示时使用参数menu_slug)。

关于settings的状态栏使用<?php settings_errors(); ?>,该函数即可显示黄色的状态栏。更多状态栏相关开发参考这个链接

 

PHP魔术函数集锦

1。construct()
实例化对象时被调用,
construct和以类名为函数名的函数同时存在时,__construct将被调用,另一个不被调用。

2。__destruct()

当删除一个对象或对象操作终止时被调用。

3。call()
对象调用某个方法,
若方法存在,则直接调用;
若不存在,则会去调用
call函数。

4。get()
读取一个对象的属性时,
若属性存在,则直接返回属性值;
若不存在,则会调用
get函数。

5。set()
设置一个对象的属性时,
若属性存在,则直接赋值;
若不存在,则会调用
set函数。

6。__toString()

打印一个对象的时被调用。如echo $obj;或print $obj;

7。__clone()

克隆对象时被调用。如:$t=new Test();$t1=clone $t;

8。__sleep()

serialize之前被调用。若对象比较大,想删减一点东东再序列化,可考虑一下此函数。

9。__wakeup()

unserialize时被调用,做些对象的初始化工作。

10。__isset()
检测一个对象的属性是否存在时被调用。如:isset($c->name)。

11。__unset()
unset一个对象的属性时被调用。如:unset($c->name)。

12。set_state()
调用var_export时,被调用。用
set_state的返回值做为var_export的返回值。

13。__autoload()
实例化一个对象时,如果对应的类不存在,则该方法被调用。

魔术常量

1。LINE
返回文件中的当前行号。

2。FILE
返回文件的完整路径和文件名。如果用在包含文件中,则返回包含文件名。自 PHP 4.0.2 起,FILE 总是包含一个绝对路径,而在此之前的版本有时会包含一个相对路径。

3。FUNCTION
返回函数名称(PHP 4.3.0 新加)。自 PHP 5 起本常量返回该函数被定义时的名字(区分大小写)。在 PHP 4 中该值总是小写字母的。

4。CLASS
返回类的名称(PHP 4.3.0 新加)。自 PHP 5 起本常量返回该类被定义时的名字(区分大小写)。在 PHP 4 中该值总是小写字母的。

5。METHOD
返回类的方法名(PHP 5.0.0 新加)。返回该方法被定义时的名字(区分大小写)。

Post Series插件(更名为SimplePostSeries)正式发布

Post Series插件改名为Simple Post Series正式在Wordpress插件官网发布,可以自由下载使用

Simple Post Series为Wordpress增加按照专题管理文章并展示的功能,集所有类似插件功能之所长,设置选项完善。

融合所有类似插件的相关功能:

  • *可以在文章编辑页面通过按钮与面板添加shortcode以展示某个专题下的文章列表,支持文章与页面,
  • *可以设置自动在文章页或主页上显示某个专题下的文章列表,可以设置展示摘要或缩略图,
  • *可以在管理员文章管理页面上对某个专题进行筛选,文章管理更加方便,
  • *2.0最新版支持文章拖拽添加到专题的功能,页面特别参考eg-series插件。
    专题文章的拖动管理页面,这是极其方便的管理页面,用户可以在该页面上自由拖动文章到某个专题,或是删除某个专题下的文章,或是改变文章的排序等。

待完善:(BUG列表)

1.页面无法在专题展示中列出

Description

simple-post-series allows you to insert series short code for displaying a bunch of posts in the same serie.
This plugin allows to include posts into series, to create, delete or rename series. It also includes widgets and shortcodes to display list of series, or the list of posts belonging to the series of the current post.

With this plugin, you can:

    • Add / Delete a post from a serie,
    • Create / Rename / Delete series,
    • Display the list of series in a post, or display this list in sidebar, with widgets for exemple,
    • Filter posts by a special serie in your admin post managent page,
    • Automatically insert the list of posts of a specific serie, without using shortcode.
      simple-post-series is TinyMCE Integrated. That means you don’t need to learn the shortcode syntax. The plugin add a button in the tinymce toolbar. You just have to click on this button, choose parameters/options, and click insert. That’s all, the shortcode will be insert into your post with the right parameters.

You can find latest source code in github project.

This plugin is enlighted by Tuts+ and their Sessions. You can find a very helpful cource in NetTuts+ to figure out how this plugin works in Wordpress.

Installation

  1. Uzip the simple-post-series.zip folder.
  2. Upload the simple-post-series folder to your /wp-content/plugins directory.
  3. In your WordPress dashboard, head over to the Plugins section.
  4. Activate Post Series.

Usage

simple post series adds two administration pages, a widget and shortcode.

Customize your theme

simple-post-series uses now a specific taxonomy to implement series. It means

    • You can build / customize a specific page in your theme to display the content of a serie.
      You can customize your theme by creating page like ‘taxonomy-series.php’ which overrides default archive page to display the content of a serie.
      A sample archive page template is located in ‘[simple-post-series]/template/taxonomy-series.php’ and you can freely modified it and place in your own theme.

Administration pages

  • * Series gives ability to change or rename series,
  • * Settings/Post Series contains all options of the plugin. In this page, you can activate the auto display feature.

Shortcodes

To display the list of series: [series options], with the following options:

  • * id of the series. Default ‘ ‘,
  • * slug of the series. Default ‘ ‘,
  • * title of the list. Default ‘ ‘,
  • * limit: number of series to display in the list. Default: -1 to display all series,
  • * show_future: displays unpublish posts in the series. Default: on,
  • * class_prefix: of the list section. Default ‘post-series’.

Screenshots

  1. Post Editing page: TinyMCE integration and additional metabox to quickly choose or add a serie 加入专题设置模块,
  2. List of posts in a serie 在文章页面展示专题列表,
  3. Easily manage series 拖拽管理专题下所属文章,
  4. TinyMCE window to choose shortcodes options, and insert shortcodes 文章编辑方便插入short code,
  5. Insert short code in edit post 插入short code的结果,
  6. Options page 插件设置页面,

Changelog

= 2.1 =

  • New: Fix bugs and improve code robustion

= 2.0 =

  • New: Add admin series bulk edition page for drag and drop posts to serie

= 1.3 =

  • New: Add option to choose where to display lists
  • New: Add option to choose to display excerpt
  • New: Add option to choose to display thumbnail

= 1.2 =

  • New: Add series filter in admin’s edit.php
  • New: optional load of the stylesheet
  • New: sample archive page for displaying series taxonomy in custom theme

= 1.1 =

  • New: add widget for post series with many options

= 1.0 =

  • Plugin released. Everything is new! Have to change name from post-series to simple-post-series.
本站总访问量