简体   繁体   English

Wordpress 单页自定义侧边栏

[英]Wordpress custom sidebar on single page

I'm trying to display a custom sidebar in a page.我正在尝试在页面中显示自定义侧边栏。 The code works with custom post types "news" posts but wont work with the page "na-midia".该代码适用于自定义帖子类型“新闻”帖子,但不适用于“na-mdia”页面。 In the page the defaul sidebar is shown.在页面中显示了默认的侧边栏。

 // 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' );

Solved!解决了!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM