jmshaw
Forum Replies Created
-
Forum: Themes and Templates
In reply to: Page slugs instead of titles in nav menu. Is it possible?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