![](/img/trans.png)
[英]Does removing the dashboard widgets cancel the SQL queries in WordPress?
[英]Missing Widgets in Wordpress dashboard?
我正在使用自己的自定義主題創建WordPress博客,並且在側欄中顯示小部件時遇到困難。 我已經將我的側邊欄注冊在functions.php中,並且正在使用get_sidebar(); 在index.php中。 如果我將內容放在sidebar.php中,它將正確顯示在邊欄中,但是我希望能夠動態修改邊欄。 但是,當我轉到外觀>小部件時,它顯示了側邊欄名稱,但“可用小部件”部分中未列出任何小部件。
這是我在函數.php中注冊邊欄的地方:
function blog_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'blog' ),
'id' => 'sidebar-1',
'description' => '',
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
}
add_action( 'widgets_init', 'blog_widgets_init' );
這是我在index.php中調用邊欄的地方:
<?php get_sidebar(); ?>
這是sidebar.php:
<?php
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
return;
}
?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</div>
有什么想法為什么在外觀>小部件中沒有可用的小部件?
編輯 :解決了! 實際上,在我的代碼中有一個地方禁用了默認小部件。 我沒有意識到那是存在的,因為它一定已經包含在我基於的主題中。 刪除了這些功能,小部件再次顯示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.