如何在wordpress生成的php中更改侧边栏?

时间:2011-06-10 18:06:21

标签: php wordpress sidebar

如何有选择地在侧边栏上显示页面?我有一些我想要显示的页面和一些我不想要的页面。具体来说,我有一些页面只是在成功注册后通知用户,我不希望在侧边栏上显示。我使用wordpress生成带有此代码的php

    <div id="primary" class="widget-area">
        <?php get_search_form(); ?>
        <ul class="xoxo">
            <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
                <li id="pages" class="widget-container">
                    <h3 class="widget-title"><?php _e('Site Map'); ?></h3>
                    <ul>
                        <?php 
                        //code that works as it is
                        wp_list_pages( 'sort_column=menu_order&title_li=&deprth=1');

                        //code that i produced and not works as excepected
                         $top_pages_to_exclude = '2, 94, 100, 123, 125, 127';
                            $args = array
                                    (
                                        'sort_column' => 'menu_order',
                                        'title_li' => '',
                                        'deprth' => 1,
                                        'exclude_tree' => $top_pages_to_exclude
                                    );
                        wp_list_pages( $args);
                        ///////////////////////////////////////////////////////////
                        ?>

                    </ul>
                </li>
                <li id = "register" class = "widget-container">
                    <h3 class = "widget-title"> <?php _e('Register / Log in '); ?></h3>
                        <form name="login" action="" method="get">  
                            To <a href="http://localhost/bill/?page_id=74">Register</a>
                            <br/>
                            <hr/>
                            Username &nbsp <input type="text" name="user" width="200" height="20" />
                            <br/>
                            <br/>
                            Password &nbsp <input type="password" name="pwd" width="200" height="20" />
                            <br/>
                            <br/>
                            <input type="submit" value="Log In" />
                        </form>
                </li>
<!--            <li id="comments" class="widget-container">
                    <h3 class="widget-title"><?php _e('Recent Comments'); ?></h3>
                    <?php $comments = get_comments('number=5&status=approve'); ?>
                    <ul>
                        <?php foreach ($comments as $comment) : ?>
                            <?php $the_post = get_post($comment->comment_post_ID); ?>
                            <li>
                                <?php echo $comment->comment_author; ?> on <a href="<?php echo get_comment_link($comment); ?>"><?php echo $the_post->post_title; ?></a>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                </li>
                <li id="categories" class="widget-container">
                    <h3 class="widget-title"><?php _e('Categories'); ?></h3>
                    <ul>
                        <?php wp_list_categories('title_li='); ?>
                    </ul>
                </li>
                <li id="links" class="widget-container">
                    <h3 class="widget-title"><?php _e('Links'); ?></h3>
                    <ul>
                        <?php wp_list_bookmarks('title_li=&categorize=0'); ?>
                    </ul>
                </li>
                <li id="archives" class="widget-container">
                    <h3 class="widget-title"><?php _e('Archives'); ?></h3>
                    <ul>
                        <?php wp_get_archives('type=monthly'); ?>
                    </ul>
                </li>
                <li id="meta" class="widget-container">
                    <h3 class="widget-title"><?php _e('Register'); ?></h3>
                    <ul>
                        <?php wp_register(); ?>
                        <li><?php wp_loginout(); ?></li>
                        <?php wp_meta(); ?>
                    </ul>
                </li>
                <li id="rss" class="widget-container">
                    <a href="<?php bloginfo('rss2_url'); ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/rss-icon.png" width="18px" height="18px" /></a> <span class="rss">Subscribe via <a href="<?php bloginfo('rss2_url'); ?>">RSS</a></span>
                </li>
-->
            <?php endif; ?>
        </ul>
    </div>     

1 个答案:

答案 0 :(得分:1)

    <?php 
    $args = array(
'depth'        => 1,
'exclude'      => '2, 94, 100, 123, 125, 127',
'title_li'     => '',
'sort_column'  => 'menu_order',
); 

    wp_list_pages( $args );
    ?>

http://codex.wordpress.org/Function_Reference/wp_list_pages具有该功能的所有选项