dongnai6973 2010-07-26 18:28
浏览 21
已采纳

如何在Wordpress中创建菜单中不可见的页面

I want to create some pages in wordpress, but I dont like these pages visible in menus. How can I create such pages ?

thanks

  • 写回答

3条回答 默认 最新

  • dongzun9958 2010-07-26 18:41
    关注

    If you're using/creating a custom theme or don't mind extending the one you're using, you could explicitly specify which page names or ids you want to be in the menu by editing the links. In my custom theme I just went in and destroyed the dynamically-generated links, replacing them with my own.

    I chose to do this in one of my own projects because I wanted to be able to have a lot of non-navigation pages without having to keep adding to exclude_pages.

    EDIT (to be more specific):

    Navigation in the default theme (wp-content/themes/twentyten) is in the header.php file and looks like this:

    <div id="access" role="navigation">
        <?php /*  Allow screen readers / text browsers to skip the navigation menu and get right to the good stuff */ ?>
        <div class="skip-link screen-reader-text"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentyten' ); ?>"><?php _e( 'Skip to content', 'twentyten' ); ?></a></div>
        <?php /* Our navigation menu.  If one isn't filled out, wp_nav_menu falls back to wp_page_menu.  The menu assiged to the primary position is the one used.  If none is assigned, the menu with the lowest ID is used.  */ ?>
        <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>
    </div><!-- #access -->
    

    If you view-source on the page this generates in a default WordPress install, it becomes the following html:

    <div id="access" role="navigation"> 
        <div class="skip-link screen-reader-text"><a href="#content" title="Skip to content">Skip to content</a></div> 
        <div class="menu">
            <ul>
                <li class="current_page_item"><a href="http://YOURSITE.COM/" title="Home">Home</a></li>
                <li class="page_item page-item-2"><a href="http://YOURSITE.COM?page_id=2" title="About">About</a></li>
            </ul>
        </div> 
    </div><!-- #access --> 
    

    So, as you can see, if you wanted to customize the navigation you would just remove that wp_nav_menu line and replace it with the appropriate html. Say you want your navigation to go to the Home, Cool Stuff and About Us pages. That could accomplished with the following code in header.php:

    <div id="access" role="navigation"> 
        <?php /*  Allow screen readers / text browsers to skip the navigation menu and get right to the good stuff */ ?>
        <div class="skip-link screen-reader-text"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentyten' ); ?>"><?php _e( 'Skip to content', 'twentyten' ); ?></a></div>
        <?php /* Our CUSTOM navigation menu. */ ?> 
        <div class="menu">
            <ul>
                <li class="<?php if (!is_paged() && is_home()) { ?>current_page_item<?php } else { ?>page_item<?php } ?>"><a href="<?php bloginfo('url'); ?>" title="Home">Home</a></li>
                <li class="<?php if (is_page('cool-stuff')) { ?>current_page_item<?php } else { ?>page_item<?php } ?>"><a href="<?php bloginfo('url'); ?>/cool-stuff" title="Cool Stuff">Cool Stuff</a></li>
                <li class="<?php if (is_page('about-us')) { ?>current_page_item<?php } else { ?>page_item<?php } ?>"><a href="<?php bloginfo('url'); ?>/about-us" title="About Us">About Us</a></li>
            </ul>
        </div> 
    </div><!-- #access --> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?