我的动态边栏不显示标准的小部件,如最近的帖子或档案,而是显示我放入边栏的单个内容。php
这是我的功能的侧边栏部分。hp:
add_action( 'widgets_init', 'my_register_sidebars' );
function my_register_sidebars() {
register_sidebar( array(
'name' => __( 'Primäre Sidebar' ),
'id' => 'sidebar-main',
'description' => __( 'Rechte Hauptsidebar für Werbeflächen und Meta' ),
'before_title' => '<h4>',
'after_title' => '</h4>',
) );
这是sidebar.php中的代码:
<aside id="sidebar-main">
<div id="widgetarea">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : endif; ?>
<h4>TESTESTEST</h4>
<p>HALLOHALLO</p>
</div>
</aside>
和往常一样,我在主题中使用<?php get_sidebar(); ?>
调用侧边栏。
为什么显示的是其他东西而不是小部件?我不知道。编辑:我已经尝试停用插件-没有变化。
您对侧边栏的调用是错误的。这个
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : endif; ?>
应该是
<?php if ( is_active_sidebar( 'sidebar-main' ) ) : ?>
<?php dynamic_sidebar( 'sidebar-main' ); ?>
<?php endif; ?>
在sidebar.hp:中尝试此操作
<aside id="sidebar-main">
<div id="widgetarea">
<?php dynamic_sidebar('Primäre Sidebar') ?>
</div>
</aside>