模板特定的WordPress侧栏

时间:2018-10-05 20:54:40

标签: wordpress templates sidebar

我正在尝试使特定的侧边栏仅显示在使用特定模板的页面上,但是我对Wordpress主题的使用并不熟悉。

“新闻侧栏”应使用home.php模板显示在页面上:

<?php 
// If the News Sidebar is active, display on the Posts page
if ( is_active_sidebar( 'sidebar-news' ) && is_page_template( 'home.php' ) ) { ?>
    <aside id="sidebar-news" class="widget-area">
        <?php dynamic_sidebar( 'sidebar-news' ); ?>
    </aside><!-- #secondary -->
<?php } ?>

1 个答案:

答案 0 :(得分:0)

如果我做对了,而您只想在该特定模板上显示该特定的侧边栏,则只需在该模板上包含<?php dynamic_sidebar( 'sidebar-news' ); ?>即可。无需执行任何逻辑,因为您已经将该模板分配给了该页面。

还要确保您命名模板,以便它显示在管理后端中。将其放在home.php的开头:

<?php
    /*
    Template Name: Home
    */
?>
相关问题