php - 单页上的 Wordpress 自定义侧边栏
问题描述
我正在尝试在页面中显示自定义侧边栏。该代码适用于自定义帖子类型“新闻”帖子,但不适用于“na-mdia”页面。在页面中显示了默认的侧边栏。
// 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';
}
推荐阅读
- python - /register/ 'AnonymousUser' 对象的 TypeError 不可迭代
- cpu - 实现 9 个 CPU 调度算法的单个程序
- linux - 我可以在 Linux 下使用 Qt Creator 上的 Alt+Tab 禁用自动完成功能吗?
- java - H2 数据库中@GeneratedValue 的问题
- node.js - discord.js EvaluatedPermissions 其他解决方案
- excel - 如果在单元格中选择了值,则为 Msgbox
- php - 没有得到数组 - PHP JSON Explode
- android-source - Aosp 下载问题
- sapui5 - 如何在 SAP Ui5 中添加验证,在输入字段中,用户端必须仅输入具有相应最大长度和最小长度的数字,
- javascript - 如何根据javascript中的对象属性对数据进行分组?