Wordpress Widget在保存时消失

时间:2013-08-08 20:44:04

标签: wordpress

我在查看了一些教程之后创建了一个自定义主题,我在使用小部件保存/显示时遇到了一些问题。每当我在管理面板中拖放一个小部件时,如果我刷新页面它就会消失并且不会显示任何内容。我用谷歌搜索了几个小时,我不是更近了。希望有人在这里看到同样的问题

从管理页面保存并重新加载后,此区域始终显示为空(没有任何小部件处于活动状态) enter image description here

我检查过的事情:

  1. 确认该ID不在Caps
  2. 验证< ?php get_sidebar(); ? >包含在page.php
  3. 禁用所有插件
  4. 将主题切换为wordpress默认设置以确认小部件实际正在运行
  5. 启用辅助功能模式(保存后不显示)
  6. 验证Jquery的最新版本
  7. 我已将其包含在 functions.php

    // Register Widget
    function ecma_widgets_init() {
        register_sidebar( array(
            'name'          => __( 'Main Widget Area', 'ecma' ),
            'id'            => 'custom1',
            'description'   => __( 'Appears in the footer section of the site.', 'ecma' ),
            'before_widget' => '<div>',
            'after_widget'  => '</div>',
            'before_title'  => '<h3 class="blue">',
            'after_title'   => '</h3>',
        ) );
    
        register_sidebar( array(
            'name'          => __( 'Secondary Widget Area', 'ecma' ),
            'id'            => 'custom2',
            'description'   => __( 'Appears on posts and pages in the sidebar.', 'ecma' ),
            'before_widget' => '<div>',
            'after_widget'  => '</div>',
            'before_title'  => '<h3 class="blue">',
            'after_title'   => '</h3>',
        ) );
    }
    add_action( 'widgets_init', 'ecma_widgets_init' );
    

    的sidebar.php

    <?php
    /**
     * The sidebar containing the secondary widget area, displays on posts and pages.
     *
     * If no active widgets in this sidebar, it will be hidden completely.
     *
     */
    
    if ( is_active_sidebar( 'home_right_sidebar' ) ) : ?>
                <div id="sidebar">
                    <?php dynamic_sidebar( 'custom1' ); ?>
                </div><!-- .widget-area -->
    <?php endif; ?>         
    

2 个答案:

答案 0 :(得分:2)

我发现$ control_ops [&#39; id_base&#39;]和parent :: __ construct()的第一个参数应该是相同的。

class MostRecentWidget extends WP_Widget {

    public function __construct() {
        $widget_ops = array(
            'classname' => 'most-recent-widget',
            'description' => 'Displays Most Recent in sidebar'
        );
        $control_ops = array(
            'id_base' => 'most-recent-widget'
        );
        parent::__construct('most-recent-widget', 'Most Recent Widget', $widget_ops, $control_ops);
    }
}

答案 1 :(得分:0)

虽然可以从头开始编写主题,但在我看来,使用underscores等首发主题必须更容易。这样,大部分基本结构都得到了解决,你可以确定任何破坏的东西都是你放在它上面的额外代码,使故障排除变得更加容易。