WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to control which pages appear in menu (22 posts)

  1. theobroma
    Member
    Posted 2 years ago #

    Hi all,

    My site has a blog component as well as an extensive collection of static pages (nearly 300).

    I currently have a hand-coded drop down menu showing selected pages in my top-of-page navigation menu.

    I created this as a work-around since my theme (Prosense) does not have native support for menus and my attempts at adding native support were unsuccessful.

    I'm ready for a new theme and am now trying out different ones, but when I select "preview" every single page on my site (nearly 300) appears in the menu.

    For example, this is the case with 2011, atahualpa, and other themes I've tried.

    I have not assigned any "parent" attributes to any pages, and I do not wish to designate subpages and end up with a huge "cascading" menu of pages and subpages.

    I just want to have 15-20 selected pages in my menu as standalone links.

    What do I need to do so that when I try out new themes (and make the switch) only the selected pages appear in the menu?

    My site is here

    Any advice would be most appreciated.

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    Most themes support wp_nav_menu which allows you to create a menu from within the appearance->menus tab. You can add and arrange menu items as you see fit

  3. theobroma
    Member
    Posted 2 years ago #

    Yes, but my current theme does not.

    What I'd like to do is make any necessary adjustments now so that when I upgrade to a new theme, I don't have all 300 pages in the menu upon launch.

    Any idea on how to do that?

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    I believe you could add something like

    register_nav_menu( 'primary', __( 'Primary Menu' ) );

    to your functions.php in your existing theme. This wouldn't change any display or anything, but it would enable the ability to create a menu.

    Then you could set the menu up before switching.

    I haven't ever had to do this....but it makes sense in my mind that this would work

  5. theobroma
    Member
    Posted 2 years ago #

    Thanks, I will try this.

  6. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    I hope it works.... I'd hate to waste your time.

  7. theobroma
    Member
    Posted 2 years ago #

    So far so good. I'm going to build the menu and then try previewing another theme to see what happens...

  8. theobroma
    Member
    Posted 2 years ago #

    Well, I created a menu, and added it to my website as a sidebar widget (the only option).

    But when I preview a new theme, I still get all 300 pages showing in the top menu

  9. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    Yeah, it would only be available as a widget unless you put more code in the theme.

    I just wanted to get you the interface to create the menu.

    I guess I don't know if you would be able to have the theme preview not display all your pages. It looks like you have to actually activate a theme and the assign your menu.....

  10. theobroma
    Member
    Posted 2 years ago #

    Hmm, well it looks like my only option then is to put my site in maintenance mode during the switch for as long it takes to tweak all the options....something I was hoping to avoid.

  11. Big Bagel
    Member
    Posted 2 years ago #

    register_nav_menu( 'primary', 'Primary Menu' );

    Template Tags/register nav menu

    Using __() seems a bit unnecessary since there's no need for translating that string. Using this in the theme's functions.php will enable that menu. But, you then need to use this where you want the menu to actually show (header.php for example):

    <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>

    Function Reference/wp nav menu

    By default, this falls back to wp_page_menu() which will display all your pages. Go to Appearance->Menus to actually create a new custom menu to replace your massive default menu.

    Appearance Menus Screen

    Also, Twenty Eleven and Atahualpa (I think) already support custom menus. Shouldn't have to do any code stuffs; Just activate the theme, create the custom menu, and you're good to go.

  12. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    @Big Bagel, it was a c/p from twentyeleven, forgot to remove the translation bit after removing the domain, no harm no foul....

  13. theobroma
    Member
    Posted 2 years ago #

    Thanks, I will have a look through the doc and try this again.

  14. Big Bagel
    Member
    Posted 2 years ago #

    @Rev. Voodoo: Indeed; doesn't hurt anything to leave it in there. I also copy/pasted from Twenty Eleven. :)

  15. theobroma
    Member
    Posted 2 years ago #

    Big Bagel, I followed your instructions and inserted
    register_nav_menu( 'primary', 'Primary Menu' ); in the theme functions file

    Then created a custom menu called "Primary Menu"

    And added this in the header: <?php wp_nav_menu( array( 'theme_location' => 'Primary Menu' ) ); ?>

    Still, every single one of my pages showed up in the menu!

    I must be doing something wrong. Or maybe there's something weird about my current theme.

  16. theobroma
    Member
    Posted 2 years ago #

    Oh, I see I changed "primary" to "Primary Menu" for the coded added to the header.....probably shouldn't have done that.

    I'll try again.

  17. theobroma
    Member
    Posted 2 years ago #

    OK, I'm making progress. I reinserted the correct code in the header and only the pages in my menu appear.

    But just as a tiny vertical list on the left hand side. Not as a horizontal menu.

    Looks like I'll have to leave it like that for preview to work, so I guess I have to put the site in maintenance mode to try different themes.

    Thanks to both of you for your help with this.

  18. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    Yeah, to get proper display, you would need to add css to your theme. When originally setting this up, I just swiped the css from twentyten to start with

    But if you are switching themes, no reason to develop css I would think

  19. theobroma
    Member
    Posted 2 years ago #

    I don't have much experience customizing things with CSS... so I'd probably end up with another mess to fix.

    Or perhaps I could just use the CSS I currently have for my hand-coded menu?

    One of the reasons I'm looking for a new theme is that my current menu doesn't render consistently. In some browsers the submenus drop down, and it others they expand horizontally.

  20. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    Well, what I did was simply copy/paste the bit of code for the menu from functions.php/header.php/style.css from twentyten to my theme when the menus first came out.

    That worked perfectly. I could then edit as I saw fit once I had everything working. Using your current css may not work well, as WP outputs it's own classes, etc

  21. theobroma
    Member
    Posted 2 years ago #

    I've uploaded some newer themes (platform, yoko) to my site for previewing and the menu feature is now behaving correctly in preview, i.e. only designated pages appearing in menu, without the menu I created actually being added live on my site. And no need to use maintenance mode. Interestingly, the problem persists in the Atahualpa theme (all pages showing up in menu), so there may be a glitch or incompatibility issue with that one.
    So this has been very helpful. Thanks again.

  22. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    I was messing around with the preview myself to see what worked. Some themes do, some do not. I wonder if it has to do with what name the menu is registered as or something.

    Either way, I'm glad it's working out for you

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags