• Hi, I’m using wp_list_pages to create a navigation menu of the static pages on my site which works as it should.

    Unfortunatly my page title is “Welcome to my home page!” and it’s slug is “home”. wp_list_pages seems to only be able to output the complete page titles and not the slugs.

    So instead of a list of slugs:
    home
    about us
    products
    contact us

    I get a list of page titles:
    Welcome to my home page
    Who we are and where we’re based
    Welcome to our online shop
    Here are our contact details

    Is there any way to fix this? Plugin or hack?

    Thanks in advance!

    John..

Viewing 1 replies (of 1 total)
  • I’ve only been playing with WP for 2 weeks and just picked up PHP for the first time this morning, so I’m sure there are better ways of doing this, but this is what I came up with. I made a file called functions.php in my theme directory that contained the following:

    <?php

    function my_list_pages($options = ”)
    {
    $pages = get_pages($options);
    $url = get_option(‘siteurl’);
    global $wp_query;
    $current_page = $wp_query->get_queried_object_id();
    $sz = count($pages);
    for ($i = 0; $i < $sz; $i++) {
    $values = get_post_custom_values(‘menu_name’, $pages[$i]->ID);
    $name = $values[0];
    if ($name != ”) {
    echo “<li class=’page_item”;
    if ($pages[$i]->ID == $current_page)
    echo ” current_page_item”;
    echo “‘>post_name . “‘ title='” . $pages[$i]->post_title . “‘>”;
    echo $name . “

    “;
    }
    }
    }

    ?>

    It won’t multiple levels of menus, but that wasn’t what I was trying to do and it doesn’t sound like what you’re trying to do either. Call this function in place of wp_list_pages, and don’t use the title_li option (this function won’t put a title on anyway). For each page you want on your menu, make a custom key/value pair. The key is menu_name and the value is the display name on the menu. The set of pages with menu_name tags are the pages that this function will return, and they will have the names you specify. Then you can make the page title whatever you want ??

    Hope this works for you…

    Jonathan

Viewing 1 replies (of 1 total)
  • The topic ‘Page slugs instead of titles in nav menu. Is it possible?’ is closed to new replies.