【问题标题】:Template Specific WordPress Sidebar模板特定的 WordPress 侧边栏
【发布时间】:2018-10-05 20:54:39
【问题描述】:

我正在尝试让特定侧边栏仅出现在使用特定模板的页面上,但我在 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 } ?>

【问题讨论】:

    标签: wordpress templates sidebar


    【解决方案1】:

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

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

    <?php
        /*
        Template Name: Home
        */
    ?>
    

    【讨论】:

    • 我会试一试,但我更愿意将所有侧边栏逻辑保留在 sidebar.php 文件中。对不起,我没有说清楚。我发布的那个 PHP sn-p 来自 sidebar.php 文件。
    猜你喜欢
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 2018-04-12
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 1970-01-01
    相关资源
    最近更新 更多