页面文件中的Wordpress小部件PHP输出
我已经为我的Wordpress主题创建了一个小部件,并希望输出其内容页面文件中的Wordpress小部件PHP输出,php,wordpress,widget,Php,Wordpress,Widget,我已经为我的Wordpress主题创建了一个小部件,并希望输出其内容 <?php if ( is_active_sidebar('content_footer') ) : ?> <div class="row"> <div class="col-lg-12 col-md-12 col-sm-12 col-12"> <div id="contentfooter"> &l
<?php if ( is_active_sidebar('content_footer') ) : ?>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-12">
<div id="contentfooter">
<?php dynamic_sidebar('content_footer'); ?>
</div>
</div><!--/.col -->
</div><!--/.row -->
<?php endif; ?>
该小部件显示在后端的小部件下,因此工作正常
下面是我的page.php文件中的代码
<?php if ( !dynamic_sidebar('Content Footer') ) : ?>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-12">
<div id="contentfooter">
</div>
</div><!--/.col -->
</div><!--/.row -->
<?php endif; ?>
不幸的是,php标记中的所有内容都没有显示出来。只是我在后端小部件中创建的原始内容
当我将条件放入HTML内容中时,它会起作用:
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-12">
<div id="contentfooter">
<?php if ( !dynamic_sidebar('Content Footer') ) : ?>
<?php endif; ?>
</div>
</div><!--/.col -->
</div><!--/.row -->
但是,即使我没有在特定页面上使用小部件,HTML代码也总是显示出来
以下是my functions.php中的小部件解压:
if ( function_exists('register_sidebar') )
register_sidebar( array(
'name' => __( 'Content Footer'),
'id' => 'content_footer',
'description' => __( 'Content Footer Area', 'twentyeleven' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h3 class="content-footer-header">',
'after_title' => '</h3>',
));
if(函数_存在('register_边栏'))
寄存器侧栏(数组)(
“名称”=>“(“内容页脚”),
'id'=>'content\u footer',
'description'=>uuu('Content Footer Area','twentyeven'),
'在小部件'=>''之前,
'在小部件'=>''之后,
“在标题“=>”之前,
“在标题“=>”之后,
));
有人知道我需要更改什么,以便仅在使用小部件区域时输出代码吗
谢谢您应该使用
is\u active\u sidebar()
检查此侧边栏中是否有小部件,然后打印其内容
<?php if ( is_active_sidebar('content_footer') ) : ?>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-12">
<div id="contentfooter">
<?php dynamic_sidebar('content_footer'); ?>
</div>
</div><!--/.col -->
</div><!--/.row -->
<?php endif; ?>
感谢您的快速回答:)但现在它不再显示小部件内容。我在functions.php中编辑了小部件的Deklation,以防它有所帮助。如果侧边栏区域“内容页脚”不为空。2.如果边栏“内容页脚”是register,这是他的名字(打字错误)。