开发者

WordPress sidebar: appear only on certain pages

开发者 https://www.devze.com 2023-02-13 04:49 出处:网络
How can I edit the php to get my WordP开发者_Go百科ress sidebar to only appear on select pages (i.e. not on the home and about pages)?

How can I edit the php to get my WordP开发者_Go百科ress sidebar to only appear on select pages (i.e. not on the home and about pages)?

I'd prefer php over css if possible.


You could create a page template that doesn't include the call to get_sidebar(), then just use that template for whichever pages you don't want your sidebar appearing on.


You can use the function is_page() in your template and rendering the sidebar only if you need to.

Small example, in sidebar.php of the twentyten theme of WordPress

<div id="secondary" class="widget-area" role="complementary">
        <ul class="xoxo">
            <?php 
             if (is_page('my-page')) { 
                  dynamic_sidebar( 'secondary-widget-area' ); }
            ?>
        </ul>
</div><!-- #secondary .widget-area -->

This little snippet outputs the sidebar only if you are in the page that has the slug 'my-page'.
Hope this helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消