首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress customizer实时预览不起作用

Wordpress customizer实时预览不起作用
EN

Stack Overflow用户
提问于 2016-06-21 16:41:11
回答 1查看 599关注 0票数 0

我正在尝试使用wordpress定制器创建一个布局选择器选项。到目前为止,除了实时预览之外,我所做的一切都是有效的。当我在定制器中更改一个选项时,例如左边的侧边栏,css应该会更改为在左侧显示侧边栏。然而,当更改一个选项时,侧边栏就消失了,取而代之的是一个与所选选项的顺序相对应的数字。有没有人能指出我的错误所在。

这是php。

代码语言:javascript
复制
function embee_customize_register( $wp_customize ) {
//All our sections, settings, and controls will be added here

//Add Layout Options section
$wp_customize->add_section('embee_layout_section_options', array(
    'title'    => __('Layout Options', 'mybasictheme'),
    'description' => 'Change various site section layouts.',
    'priority' => 1,
));

$wp_customize->add_setting('embee_layout_section_options[site_layout]', array(
    'default'        => '3',
    'capability'     => 'edit_theme_options',
    'transport'      => 'postMessage',
    'type'           => 'option',
));

$wp_customize->add_control( 'select_box', array(
    'settings' => 'embee_layout_section_options[site_layout]',
    'label'   => 'Site Layout',
    'section' => 'embee_layout_section_options',
    'type'    => 'select',
    'choices'    => array(
        '1' => 'Left Sidebar',
        '2' => 'Right Sidebar',
        '3' => 'Three Column',
        '4' => 'Full Width',
    ),
    'description' => 'Change sidebar layouts.',
));
}
add_action( 'customize_register', 'embee_customize_register' );

function embee_customizer_live_preview()
{
wp_enqueue_script( 
      'embee-customizer',           //Give the script an ID
      get_template_directory_uri().'/mbpanel/js/customizer.js',//Point to file
      array( 'jquery','customize-preview' ),    //Define dependencies
      '',                       //Define a version (optional) 
      true              //Put script in footer?
);
}
add_action( 'customize_preview_init', 'embee_customizer_live_preview' );

function layout_customize_css()
{
$options = get_option( 'embee_layout_section_options' );
?>
     <style type="text/css">
        #content { <?php if( $options['site_layout'] == '1' ) { ?> float: right; <?php } ?> } #sidebar_primary { <?php if( $options['site_layout'] == '1' ) { ?> float: left; <?php } ?> }
        #content { <?php if( $options['site_layout'] == '2' ) { ?> float: left; <?php } ?> } #sidebar_primary { <?php if( $options['site_layout'] == '2' ) { ?> float: right; <?php } ?> }
        #content { <?php if( $options['site_layout'] == '3' ) { ?> float: left; <?php } ?> } #sidebar_primary { <?php if( $options['site_layout'] == '3' ) { ?> float: left; <?php } ?> } #sidebar_secondary { <?php if( $options['site_layout'] == '3' ) { ?> float: left; <?php } ?> }
        #content { <?php if( $options['site_layout'] == '4' ) { ?> float: none; width: 100%; <?php } ?> }
     </style>
<?php
}
add_action( 'wp_head', 'layout_customize_css');

这是javascript

代码语言:javascript
复制
( function( $ ) {
wp.customize( 'embee_layout_section_options', function( value ) {
    value.bind( function( to ) {
        $( '#sidebar_primary' ).css( 'float', 'left' );
    } );
} );

} )( jQuery );

EN

回答 1

Stack Overflow用户

发布于 2017-05-17 02:28:34

添加以下行:

代码语言:javascript
复制
<?php wp_footer(); ?>   
/*Just Before </body> tag */

这通常发生在customize_preview_init实际将JavaScript排在文件末尾的时候。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37939500

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档