Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: wp_page_menu issues

  1. #1
    Cais's Avatar
    Cais is offline Big Tipper
    Join Date
    Feb 2009
    Location
    Mississauga, ON, CANADA
    Posts
    349

    Default wp_page_menu issues

    Somewhere in my recent readings I came across the wp_page_menu function and decided to look into it a bit further.

    I noticed in the codex that it did not seem to accept an "exclude" argument which I found rather odd so I looked deeper and started to play around a bit on my sandbox site.

    Here are some screenshots of what I found (default):





    ...and here with an undocumented exclude argument:





    Notice that the "Child page1" has a child page in the default; and then how when excluded the "Child page 2" displays on the same level as the "Parent" page ... and that's not to mention the actual layout issues with the Parent page.

    The best I could find in trac was this ticket: http://core.trac.wordpress.org/ticket/8298

    The question(s): does anyone know if this is related or a new bug? or, has it been ticketed already and I just have not found the ticket, yet?

    It was looking like such a nice function to work into my latest theme ... but not now.

    (PS: Sorry about the wide images ...)

  2. #2
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

    Default

    Isn't it just wp_list_pages() with a pointless wrapper tag added?

  3. #3
    Cais's Avatar
    Cais is offline Big Tipper
    Join Date
    Feb 2009
    Location
    Mississauga, ON, CANADA
    Posts
    349

    Default

    Quote Originally Posted by Ryan View Post
    Isn't it just wp_list_pages() with a pointless wrapper tag added?
    I haven't checked, yet, but does wp_list_pages() have the same issue with excluded (child) pages?

    Otherwise, I would agree the two functions are very similar. The defaults of wp_page_menu() does simplify similar code you would generally need to write when using wp_list_pages(). The difference essentially being the added class="menu" wrapper tag.

  4. #4
    BinaryMoon's Avatar
    BinaryMoon is offline Hello World
    Join Date
    Jun 2009
    Posts
    56

    Default

    I thought wp_page_menu just wrapped wp_list_pages and added a home link at the start. I'd also be interested to know if the same thing happens with wp_list_pages.

  5. #5
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

    Default

    Yeah, the wp_list_pages() function does behave a little odd when you start removing parent pages. I'm not sure if it does what you are suggesting above, but I'd assume so since I'm certain wp_list_menu() is basically the exact same thing.

    AFAIK there is no point in using wp_list_menu(), it's a pointless function.

  6. #6
    Cais's Avatar
    Cais is offline Big Tipper
    Join Date
    Feb 2009
    Location
    Mississauga, ON, CANADA
    Posts
    349

    Default

    Quote Originally Posted by BinaryMoon View Post
    I thought wp_page_menu just wrapped wp_list_pages and added a home link at the start. I'd also be interested to know if the same thing happens with wp_list_pages.
    Looking at both functions in trunk would have me agree with this ... and I suspect wp_list_pages() would behave near identical, I'll have to test it later.

    http://core.trac.wordpress.org/brows...t-template.php if anyone wants to read more (around line 728).

    It makes using wp_list_pages('depth=1') as a starting point for menus much more sensible than I realized before.

    <edit>
    FYI: wp_list_pages() exhibits the exact same behavior as wp_page_menu() when tested with the same excluded page.
    Looks like I may be going with wp_page_menu after all, especially given the discussions at Digging Into WordPress.
    </edit>
    Last edited by Cais; 07-13-2009 at 11:23 PM. Reason: Note re:wp_list_pages and exclude test

  7. #7
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

    Default

    I take back everything bad I said about wp_page_menu(). It's not pointless at all and is in fact quite useful. Although it literally just adds a wrapper tag around the wp_list_pages() function (plus maybe a few other minor features), it also acts as a hook, which for a theme itself is not of any real use. You could easily add your own hook anyway.

    Where wp_page_menu() becomes useful IMO is with plugins. Tonight I setup my new plugin so that it can unhook the existing menu and totally replace it with my own. This gives infinite flexibility to the way the menu works via simple plugin. Typically to modify the menu in any fancy kinda of way you would need to manually modify the theme files, but since wp_page_menu() is a hook, the plugin can simply strip out the existing menu and replace it with whatever you want.

    The following for example would strip out the existing menu and replace it with a different menu which has no DIV tag and displays categories instead of pages.
    Code:
    function test() { ?>
       <ul>
          <?php list_categories(); ?>
       </ul>
    <?php }
    add_action('wp_page_menu','test');
    Last edited by Ryan; 07-27-2009 at 05:22 AM.

  8. #8
    Dan Schulz's Avatar
    Dan Schulz is offline Hello World
    Join Date
    Jan 2009
    Location
    Aurora, Illinois
    Posts
    31

    Default

    And as Ryan and I were talking about over MSN tonight, you'd just call wp_page_menu(); normally in your Theme file, but put the above code in your functions.php file - nifty, huh?

  9. #9
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

    Default

    Yep, or if you wanted to keep it all in one place you could do this:
    Code:
    <?php
    function test() { ?>
       <ul>
          <?php list_categories(); ?>
       </ul>
    <?php }
    add_action('wp_page_menu','test'); ?>
    <?php wp_page_menu(); ?>
    Placing the function and add_action into your functions.php file makes the regular themes files easier to read, but doing the above way makes sure it's all in one spot. Personally I'd move it to the functions.php file, although I can see why leaving it the regular theme file itself may be less confusing since the menu code isn't split across two different files.

  10. #10
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,797

    Default

    BTW, hat tip to Justin Tadlock who's comments about wp_page_menu() made me realise this was possible

Page 1 of 3 123 LastLast

LinkBacks (?)

  1. 07-14-2009, 10:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •