emlog 模板设置插件
插件介绍长期以来,emlog 走的是轻量级路线,不集成模板后台设置,所以很多强大的模板需要修改文件才能更改设置。那么,有了这个插件,你就不用这么纠结了。只要按照开发规范开发模板,就可以使用这个插件在后台进行设置。
如何让插件识别模板?
将options.php放到模板目录下,内容格式如下,可以任意添加设置项,注意$options变量和注释:
<?php
/*@support tpl_options*/
!defined('EMLOG_ROOT') && exit('访问权限已定义!');
$选项 = 数组(
'侧边栏' => 数组(
'类型' => '收音机',
'名称' => '侧边栏位置',
'值' => 数组(
'左' => '左',
'正确' => '正确'
),
'默认' => '正确',
),
'sortIcon' => 数组(
'类型' => '图像',
'name' => '分类图标设置',
'值' => 数组(
模板网址。 '图像/star.png',
),
'依赖' => '排序',
'未排序' => 真的,
'description' => '为不同的分类设置不同的小图标,最好是20×20',
),
);
在 options.php 中,每个元素应该写什么?
如上图,$options数组中,key为设置项的id,value为包含多个元素的数组。 type属性和name属性是必须的,name是设置项的名称,type用来指定设置项的类型。支持的类型如下:
单选:单选按钮
复选框:检查按钮
文字:文字
图片:图片
页:页
排序:排序
标签: 标签
对于所有类型,默认属性用于指定默认值。不指定default时,使用values中的第一个值。如果两者都没有指定,则使用一个奇怪的默认值。
对于radio和chexkbox,values属性用来设置每个按钮的值和显示名称。
除了sort,可以指定depend为sort,也就是说这个选项可以根据不同的类别设置不同的值。当指定依赖为排序时,可以选择未排序的属性。为true时,表示包含unsorted,不包含false。默认为真。
sort 和 page 可以将 multi 属性设置为 true,表示多选。
description 属性是可选的,用于描述选项。
如果type为text,multi属性可以设置为true,表示多行文本,即input和textarea的区别。可选属性rich 用于支持富文本。如果设置了此值,则将加载编辑器。
如果type是sort、page或tag,并且设置了多选,则默认值为空,否则为该类型的第一个值。
如何调用模板中的设置项
插件提供了一个简单的方法 *_g($key),如上例,可以使用 _g('sidebar') 获取侧边栏的设置,值为 0 或 1,使用 _g('sortIcon' ) 要获取类别图标的所有设置,使用 _g('sortIcon.1') 以类别 id 为键的数组获取类别 id 为 1(如果存在)的 sortIcon。需要注意的是,对于页面类型,会获取页面id,排序类型,获取类别id,标签类型,获取标签名称。如果不传递任何参数,则所有设置都将使用 _g() 方法获取。对于迁移的旧模板,可以使用 extract(_g());* 替换原来的加载选项文件。
(Plug in introductionFor a long time, emlog has taken a lightweight route and does not integrate template background settings. Therefore, many powerful templates need to modify files to change settings. Well, with this plug-in, you don't have to be so tangled. The plug-in can be developed in the background according to this specification.How to make the plug-in recognize the template?Set options PHP is placed in the template directory. The content format is as follows. You can add any setting item. Note the $options variable and comments:<? php/*@support tpl_ Options*/! Defined ('emlog_root ') & & exit ('Access rights defined!');$option = array('sidebar '= > array('type '= >' radio ','name' = > 'sidebar position','value' = > array('left' = > 'left','correct' = > 'correct'),'default '= >' correct ',),'sorticon '= > array('type '= >' image ','name' = > 'classification icon settings','value' = > array(Template URL. ' Image / star png',),'dependency '= >' sort ','not sorted' = > really,'description '= >' set different small icons for different categories, preferably 20 × 20',),);In options What should each element write in PHP?As shown in the figure above, in the $options array, key is the ID of the setting item and value is the array containing multiple elements. The type attribute and name attribute are required. Name is the name of the setting item, and type is used to specify the type of the setting item. The supported types are as follows:Radio: radio buttonCheck box: check buttonText: TextPicture: picturePage: pageSorting: sortingLabels: labelsSpecifies the default value for all attributes. When default is not specified, the first value in values is used. If neither is specified, a strange default value is used.For radio and chexkbox, the values attribute is used to set the value and display name of each button.In addition to sort, you can specify depend as sort, that is, this option can set different values according to different categories. When a dependency is specified as sort, you can select an unsorted attribute. When it is true, it means that it contains unsorted and does not contain false. The default is true.Sort and page can set the multi attribute to true, indicating multiple choices.The description attribute is optional and is used to describe the options.If the type is text, the multi attribute can be set to true, indicating the difference between input and textarea. The optional property rich is used to support rich text. If this value is set, the editor loads.If the type is sort, page or tag, and multiple selections are set, the default value is empty; otherwise, it is the first value of the type.How to call a setting item in a templateThe plug-in provides a simple method*_ G ($key), as in the above example, can be used_ G ('sidebar ') get the setting of the sidebar. The value is 0 or 1. Use_ G ('sorticon ') to get all the settings of the category icon, use_ G ('sorticon. 1 ') the array with category ID as the key gets the sorticon with category ID of 1 (if any). It should be noted that for the page type, the page ID, sorting type, category ID, tag type and tag name will be obtained. If no parameters are passed, all settings are used_ G () method. For the migrated old template, you can use extract (_g())* Replace the original load options file.)
页:
[1]