WordPress自定义侧边栏在单个页面上



我正在尝试在页面中显示自定义侧边栏。该代码适用于自定义帖子类型"新闻"帖子,但不适用于页面"na-midia"。在页面中,将显示 defaul 侧边栏。

// Custom Sidebar
function prefix_custom_sidebar() {
register_sidebar( array(
'name'          => __( 'Custom Sidebar Mídia', 'page-builder-framework' ),
'id'            => 'custom-sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget'  => '</div>',
'before_title'  => '<h4 class="wpbf-widgettitle">',
'after_title'   => '</h4>'
) );
}
add_action( 'widgets_init', 'prefix_custom_sidebar' );
// Replace the default sidebar with our new custom sidebar on all docs posts
function prefix_do_custom_sidebar( $sidebar ) {
// this statement works for custom post types
if( is_singular( 'news' ) ) {
$sidebar ='custom-sidebar';
}
// this statement NOT works for the page which is displaying the posts, display the default sidebar instead
elseif ( is_singular( 'na-midia' ) ) {
$sidebar ='custom-sidebar';
}
return $sidebar;
}
add_filter( 'wpbf_do_sidebar', 'prefix_do_custom_sidebar' );

解决了!

elseif ( is_page ( 'na-midia' ) ) {
$sidebar ='custom-sidebar';
}

最新更新