名称:它控制选项的显示名称。id:此参数分配一个唯一的名称,该名称在整个过程中用于检索保存的选项值。desc:此参数添加带有选项名称的简短描述。default:设置默认的 color 值。实时预览:(可选)它有助于显示主题定制器部分内更改的实时预览。css:(可选)当您在管理页面和/或主题定制器部分添加 color 选项时,它会自动生成 CSS。
createOption( array( 'id' => 'aa_color', // The ID which will be used to get the value of this option 'type' => 'color', // Type of option we are creating 'name' => 'My Color Option', // Name of the option which will be displayed in the admin panel 'desc' => 'This is our option', // Description of the option which will be displayed in the admin panel 'default' => '#fffff' // Default value of the option which will be displayed in the admin panel ) );
我在管理面板 $aa_panel 中创建了一个 color 类型选项。然后,通过 createOption() 函数,我添加了一个 color 类型选项,其 ID 为 aa_color。该函数采用选项类型支持的参数数组。因此,会相应地使用 id、type、name、desc 和默认参数。请注意 id 的值,即aa_color,应该始终是唯一的。
上面的屏幕截图显示了一个名为 My Color Option 的 color 选项在Neat Options管理面板中。
createOption( array( 'id' => 'aa_color_in_tab1_panel2', // IDs should always be unique. The ID which will be used to get the value of this option 'type' => 'color', // Type of option we are creating 'name' => 'My Color Option', // Name of the option which will be displayed in the admin panel 'desc' => 'This is our option', // Description of the option which will be displayed in the admin panel 'default' => '#fffff' // Default value of the option which will be displayed in the admin panel ) );
这次我在管理选项卡 $aa_tab1 内创建了一个 color 类型选项。该选项的 ID 为 aa_color_in_tab1_panel2,该 ID 应该是唯一的。
我将通过 getInstance() 函数获取一个实例,然后使用 getOption() 函数。在此函数(第 5 行)内,我输入 ID aa_color_in_tab1_panel2 作为其参数。最后,我创建了一个div并以文本形式打印了保存的值。
在前端显示结果
这次我选择了 #0bc47d 作为我的颜色值。因此,输出将像这样打印:
在 Metabox 内创建颜色类型选项
声明示例
createOption( array( 'id' => 'aa_mb_color', // The ID which will be used to get the value of this option 'type' => 'color', // Type of option we are creating 'name' => 'My Color Option', // Name of the option which will be displayed in the admin panel 'desc' => 'This is our option', // Description of the option which will be displayed 'default' => '#fffff' // Default value of the option which will be displayed ) );
现在,我将通过 createOption() 函数在元框 $aa_metbox 中创建一个 color 类型选项。该选项的 ID 为 aa_mb_color,用于检索保存的选项值。元框出现在所有帖子/页面编辑屏幕上。
接下来看第 19 行,我在 div 中使用了内联 CSS 样式。这意味着 color 类型选项的值在前端显示为颜色。
在前端显示结果
我选择 #ffff00 作为我的十六进制颜色值并发布了该页面。这是我得到的:
现在您可以在上面的屏幕截图中看到保存的值显示为颜色,并且整个 div 更改其背景颜色.
在主题定制器中创建颜色类型选项
声明示例
createOption( array( 'id' => 'aa_sec_body_bg_clr', // The ID which will be used to get the value of this option 'type' => 'color', // Type of option we are creating 'name' => 'Site Background Color',// Name of the option which will be displayed in the admin panel 'default' => '#fff' // Default value of our option ) );
createOption() 函数在主题定制器部分 $aa_section1 中添加 color 类型选项。该选项的ID是aa_sec_body_bg_clr,用于设置body背景颜色。
createOption( array( 'id' => 'aa_img_id', // The ID which will be used to get the value of this option 'type' => 'upload', // Type of option we are creating 'name' => 'My Upload Option', // Name of the option which will be displayed in the admin panel 'desc' => 'This is our option' // Description of the option which will be displayed in the admin panel ) );
我将通过 createOption() 函数在管理面板 $aa_panel 中添加一个 upload 类型选项。该函数采用一系列参数,例如id、type、name和desc。保持您的 ID 唯一,因为这些 ID 将在整个过程中用于检索保存的值。所以,这里的 ID 是 aa_img_id。
createOption( array( 'id' => 'aa_img_in_tab1_panel2', // IDs should always be unique. The ID which will be used to get the value of this option 'type' => 'upload', // Type of option we are creating 'name' => 'My Upload Option', // Name of the option which will be displayed in the admin panel 'desc' => 'This is our option' // Description of the option which will be displayed in the admin panel ) );
在管理选项卡 $aa_tab1 内创建 ID 为 aa_img_in_tab1_panel2 的 upload 选项。
您可以在管理面板Neat Options 2标签 1 内找到此选项/strong>.
用法示例
让我们获取保存的值。
getOption( 'aa_img_in_tab1_panel2' );/** * Print the value saved in option */$aa_img_in_tab1_panel2_URL_val= 'http://placehold.it/500x500';if ( is_numeric( $aa_img_in_tab1_panel2_val ) ) { $aa_img_in_tab1_panel2_attachment = wp_get_attachment_image_src($aa_img_in_tab1_panel2_val ); $aa_img_in_tab1_panel2_URL_val = $aa_img_in_tab1_panel2_attachment[0];} ?>
The image in Tab 1 is shown below:
<img src='' />
在前端显示结果
我再次上传了相同的图像并保存了它。在前端看起来像这样:
在 Metabox 内创建上传类型选项
声明示例
现在我将在元框中创建此选项。
createOption( array( 'id' => 'aa_mb_img', // The ID which will be used to get the value of this option 'type' => 'upload', // Type of option we are creating 'name' => 'My Upload Option', // Name of the option which will be displayed in the admin panel 'desc' => 'This is our option' // Description of the option which will be displayed in the admin panel ) );
getOption( 'aa_mb_img', get_the_ID() );/** * Print the value saved in option */$aa_mb_img_URL_val= 'http://placehold.it/500x500';if ( is_numeric( $aa_mb_img_val ) ) { $aa_mb_img_attachment = wp_get_attachment_image_src($aa_mb_img_val ); $aa_mb_img_URL_val = $aa_mb_img_attachment[0];} ?>
The image in Metabox is shown below:
<img src='' />
在前端显示结果
我们在前端查看结果:
在主题定制器部分中创建上传类型选项
声明示例
最后,我将在定制器中创建一个图像上传器字段。
createOption( array( 'id' => 'aa_sec_img', // The ID which will be used to get the value of this option 'type' => 'upload', // Type of option we are creating 'name' => 'My Upload Option',// Name of the option which will be displayed in the admin panel 'desc' => 'This is our option' // Description of our option ) );
upload 类型选项显示在主题定制器部分 $aa_section1 内。它的 ID 是 aa_sec_img。
您可以在上图中的我的部分自定义面板中找到上传者字段。
用法示例
使用以下代码获取值:
getOption( 'aa_sec_img' );/** * Print the value saved in option */ $aa_sec_img_URL_val= 0;if ( is_numeric( $aa_sec_img_val ) ) { $aa_sec_img_attachment = wp_get_attachment_image_src($aa_sec_img_val ); $aa_sec_img_URL_val = $aa_sec_img_attachment[0];} ?>
在这篇文章中,我们将了解 html 和 xml 之间的区别。 HTML 它指的是超文本标记语言。 它有助于创建网页和应用程序。 它是一种标记语言。 它也有助于创建静态页面。 立即学习“前端免费学习笔记(深入)”; 它有助于显示数据。 它不传输数据。 超文本有助于定义多个网页之间的链接。 标记语言有助…
使用html表单,您可以轻松获取用户输入。使用标签来添加表单元素以获取用户输入。不同类型的表单元素包括文本输入、单选按钮输入、提交按钮等。 标签通过使用type属性帮助您获取用户输入。要清除HTML表单中的所有输入,请使用带有type属性为reset的标签。 Example 1 以下示例演示了如何清…
在本文中,我们将学习如何限制HTML输入框,使其仅接受数字输入。 We use the to limit an HTML input box so that it only accepts numeric inputs. By using this, we will get a numeric in…
In this article we are going to learn about how to create teletype text in HTML. 使用电传机或打字机风格的等宽字体来显示由标签创建的内联文本。 等宽字体、单一字体和非比例字体都指的是同一件事。它们都指的是一种字体,其字符…