我已经为WordPress主题创建了一个自定义部分, 但是, 每当打印该部分时, 都会添加内联样式以隐藏该部分。这是节声明, 自定义节注册及其用法:
<
?php/* Theme Test Data */
class theme_test_data extends WP_Customize_Section {
public $type = "theme_test_data";
public $test_url = "";
public $test_text = "";
public $test_link_text = "";
public function json() {
$json = parent::json();
$json['test_text'] = $this->
test_text;
$json['test_link_text'] = $this->
test_link_text;
$json['test_url']= esc_url( $this->
test_url );
return $json;
}public function render_template() {?>
<
li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }}">
<
form method="POST" action="{{data.test_url}}">
<
input type="hidden" name="testdatainstall" value="http://www.srcmini.com/1"/>
<
?php wp_nonce_field('theme.initialize');
?>
<
h3 class="accordion-section-title">
<
span>
{{data.test_text}}<
/span>
<
button type="submit" class="theme_customizer_doc_button btn">
{{data.test_link_text}}<
/button>
<
/h3>
<
/form>
<
/li>
<
?php }
}//Theme registration
$wp_customize->
register_section_type( 'theme_test_data' );
//Add section
$wp_customize->
add_section(new theme_test_data($wp_customize, 'theme_test_data', array(
'title'=>
__('Section Title', 'theme_language'), 'test_url'=>
admin_url('edit.php'), 'test_text' =>
__('Install our test data', 'theme_language'), 'test_link_text' =>
__('Install', 'theme_language'), 'priority' =>
1000
)));
但是, 在HTML输出中, 其呈现方式如下:
<
li id="accordion-section-theme_test_data" class="accordion-section control-section control-section-theme_test_data" aria-owns="sub-accordion-section-theme_test_data" style="display: none;
">
<
form method="POST" action="{hiddenforprivacy}">
<
input name="testdatainstall" value="http://www.srcmini.com/1" type="hidden">
<
input id="_wpnonce" name="_wpnonce" value="http://www.srcmini.com/24923e18ae" type="hidden">
<
input name="_wp_http_referer" value="http://www.srcmini.com/wp/wp-admin/customize.php?return=%2Fwp%2Fwp-admin%2Fedit.php" type="hidden">
<
h3 class="accordion-section-title">
<
span>
Install our test data<
/span>
<
button type="submit" class="theme_customizer_doc_button btn">
Install<
/button>
<
/h3>
<
/form>
<
/li>
你有什么头绪吗?我都试过了:(
#1【WordPress的自定义器隐藏自定义section()】WordPress部分由HTML结构和JavaScript部分组成。我没有通过JavaScript将该部分设置为始终处于活动状态。我做了如下:
api.sectionConstructor['theme_test_data'] = api.Section.extend( {// No events for this type of section.
attachEvents: function () {}, // Always make the section active.
isContextuallyActive: function () {
return true;
}
} );
推荐阅读
- WordPress-定制程序设置会覆盖以前的设置
- WordPress自定义器自定义控件传输postMessage不起作用
- WordPress自定义不起作用-load-scripts.php错误
- WordPress(通过过滤器自定义Ajax请求响应)
- WordPress自定义标题-错误
- 将Adsense代码添加到header.php后,WordPress CSS无法加载
- WordPress自定义3级超级菜单
- 运用万能5笔输入法打不出火星文的处理办法
- WinRAR自动压缩、加密的设置办法