[英]Widget content isn't showing on pages in wordpress
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.小部件的内容仅在类别页面中可见。 eg
archive.php
.例如
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在footer.php我有
<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();
刚刚改变了
get_sidebar();
to dynamic_sidebar( 'sidebar' );
到
dynamic_sidebar( 'sidebar' );
Widget function in functions.php
在
functions.php
小部件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
)
Add this code in functions.php在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在 footer.php 文件中使用它
<div class="newsletter">
<?php dynamic_sidebar( 'stay_connected_widget' ); ?>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.