duanjianao0592 2019-01-24 10:59
浏览 63
已采纳

窗口小部件中的窗口小部件内容未显示

I have a standard widget which I've included in my footer with

<?php get_sidebar(); ?>

The content of the widget is visible only in categories pages. e.g. archive.php.

How can I show it on other pages too? It is included with the footer on all pages, like this:

<?php get_footer(); ?>

In the footer.php I have

<div class="footer-center" data-equalizer-watch>
   <div class="baseline">
       <div class="newsletter">
            <?php get_sidebar(); ?>
       </div>
   </div>
</div>

UPDATE

<div class="newsletter">
     <?php dynamic_sidebar( 'sidebar' ); ?>
</div>

Just changed get_sidebar(); to dynamic_sidebar( 'sidebar' );

Widget function in functions.php

//Stay Connected widget
add_filter( 'widget_text', 'do_shortcode' );

function stay_connected_load_widget() {
    register_widget( 'stay_connected_widget' );
}
add_action( 'widgets_init', 'stay_connected_load_widget' );

class stay_connected_widget extends WP_Widget { 
    function __construct() {
        parent::__construct( 
            'stay_connected_widget',  
            __('Stay Connected', 'stay_connected_widget_domain'), 
            array( 'description' => __( 'Social networks and subscribe form', 'stay_connected_widget_domain' ))
        );
    }

    //Widget frontend
    public function widget( $args, $instance ) {
        $cf7_form = apply_filters( 'widget_title', $instance['cf7_form'] );
        echo $args['before_widget'];
    //  echo $args['before_title'] . '<h4>' .  __( 'Stay Connected', 'stay_connected_widget_domain' ) . '</h4>' .$args['after_title'];
        ?>

        <?php           
        if(!empty( $cf7_form )){
            echo '<h4 class="form_title">'. __('Subscribe By Email').'</h4>';
            echo '<div class="stay_connected_form">'.do_shortcode(html_entity_decode($cf7_form)).'</div>';
        }       
        echo $args['after_widget'];
    }

    // Widget Backend 
    public function form( $instance ) {
        if ( isset( $instance[ 'cf7_form' ] ) ) {
            $cf7_form = $instance[ 'cf7_form' ];
        }
        else {
            $cf7_form = __( '', 'stay_connected_widget_domain' );
        }
        ?>
        <p>
            <label for="<?php echo $this->get_field_id( 'cf7_form' ); ?>"><?php _e( 'Contact Form:' ); ?></label> 
            <input class="widefat" id="<?php echo $this->get_field_id( 'cf7_form' ); ?>" name="<?php echo $this->get_field_name( 'cf7_form' ); ?>" type="text" value="<?php echo esc_attr( $cf7_form ); ?>" placeholder="[<?php _e('contact form shortcode'); ?>]"/>
        </p>
        <?php 
    }
    public function update( $new_instance, $old_instance ) {
        $instance = array();
        $instance['cf7_form'] = ( ! empty( $new_instance['cf7_form'] ) ) ? strip_tags( $new_instance['cf7_form'] ) : '';
        return $instance;
    }
}

Update

Array ( 
    [wp_inactive_widgets] => Array ( ) 
    [header] => Array ( 
        [0] => media_gallery-2 
    ) 
    [footer] => Array ( 
        [0] => custom_html-2 
    ) 
    [sidebar] => Array ( 
        [0] => stay_connected_widget-3 
        [1] => search-2 
    ) 
    [array_version] => 3 
)
  • 写回答

1条回答 默认 最新

  • duanhong8839 2019-01-24 12:13
    关注

    Add this code in functions.php

    function stay_widgets_init() {
    
        register_sidebar( array(
            'name'          => 'Stay Connected ',
            'id'            => 'stay_connected_widget',
            'before_widget' => '<div>',
            'after_widget'  => '</div>',
            'before_title'  => '',
            'after_title'   => '',
        ) );
    
    }
    add_action( 'widgets_init', 'stay_widgets_init' );
    

    Use this in footer.php file

    <div class="newsletter">
         <?php dynamic_sidebar( 'stay_connected_widget' ); ?>
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛