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 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题