Getting wp_list_pages to output page name instead of page title
this one is driving me mad. Some time ago I had a go at this and only got a part solution. What I wish to do is allow my users to utilise the page stub / permalink / page name of a post or page instead of the title – so that navigations in the sidebar are neater and controllable.
For example, if I have a page titled ‘What we did on our holidays’ – and the template only has a narrow sidebar, its going to look messier. I would like to be able to set the permalink / page name to ‘Our Holidays’ instead.
I recently revisited this idea because my solution – though it delivered the page names and the links it didn’t handle any subpages correctly. I essentially want the function of wp_list_pages, but have it return page name within the
- construct instead of page_title
I spent some time reverse engineeing wp_list_pages, and trying to understand how the the walk and page_walk functions plus the filter work, but its getting somewhat beyond me. I cannot locate the wp_page_list filter, or maybe don’t understand the mechanism right.
Can anyone help or suggest a solution?
The name/slug cannot have spaces in it. The slug is used to build the URL, not for any other purpose.
Why not just change the Title of the Page to “Our Holidays”, then put “What we did on our holidays” in the Page content itself. Then you can make a Page Template which doesn’t show the Title on it, and nobody will ever know the difference.
Essentially because it is inflexible. In my own attempt I converted the spaces and underscores with string-replace before using it to populate the Anchor.
It need not be the slug that is used, I know of one attempt at a plugin that extends the edit page with a box allowing the user to alter the ‘name’ of the page as it is used in all Navigations, but alas, the plugin doesn’t seem to work in 2.6.1+ or WPMU 2.6 at all.
Would you mind giving the plugin another try? There’s a more recent version than the one you used which fixes the only bug reported so far.
If it still doesn’t work for you, I’d really appreciate an email (to tim @ technokinetics .com) with the details so that I can try to figure out why. I’d rather not release this if it isn’t going to work for a significant number of users. Thanks.
I’ll also look into making it WPMU compatible in a future version.
Of course I will Techno – many thanks for putting the effort it.
In the end I managed to trace how the wp_list_page function (eventually) filters its output via the extended class Walker_Page. So on a theme by theme basis and without any kind of elegance I can put a mutated class steves_Walker_Page and siimilar copies of wp_list_pages etc.
Its just not elegant really.
Im working up to learning plugins you see :00
thanks again both for input, I will certainly try out the new copy of the plugin Techno!
Good luck with the plugin.
If you want to look at doing this manually (e.g. for WPMU), you can:
(a) Store the output of wp_list_pages in a variable using
$page_menu_list = wp_list_pages('echo=0');
(b) Replace long titles with short titles using
$page_menu_list = preg_replace('/Long Title/','Short Title',$page_menu_list);(repeat as required for multiple replacements)
(c) Output the result using
Technokinetics, great Pages plugin. Thanks for creating it — saved me a lot of grief just now.
Thanks for the feedback, Tom; always useful.
I was looking for how to have “real” page names in wp and came across this thread. What plugin are you mentioning? Does it do what I am looking for? Have I missed something fundamental about WP because this seems like a useful thing for several reasons.
I want a name like lessonlist.html instead of ?page=205. It’s a whole lot easier to tell someone to go to the former. I’m trying to replace a current website with wp and this REALLY gets in the way, ya know? Also, I just ran into having to change flash “movies”. Current is something like “…/lessonlist.html#3” for a pointer in the flash file. I need to make that something like “…/?page=205#3”. Now, doesn’t that seem obtuse and just asking for trouble? (and I can’t just simply use this flash file which was built in 1999!!)
It just seems that there are several reasons for letting people name pages as fixed anchors, entry points, talking points, replacement pages/systems, etc. instead of being forced into some automatically generated page “name”. I’d like to be sure that “lessonlist.html” doesn’t change on me – and also, lessonlist means a whole lot more and is easier to remember than ?page=207 (or did he say 205…or..). OK, so I try not to be a supreme geek and make everything obtuse and hard to use, explain, etc…hmmm..
So, what is this plugin (I tried looking for it a couple of ways) and will it let me name individual pages? (Or am I missing something fundamental that already lets me name individual pages?)
thx! — Joe B.
As I “walked away”, I think I realized part of the problem – wp doesn’t just make pages, it **needs** to control them (a control freak) and it does this through the “/?page” mechanism. It doesn’t really create pages. For what I want, it would have to **actually** create them (like my other site editors do). Maybe that’s why this useful feature doesn’t seem to exist? Hmmm…. well, it still leaves me with a couple of problems which wp just doesn’t seem to solve..
WP does let you create user-friendly urls on a page-by-page basis; no need for a plugin. See the Using Permalinks page in the codex for details.
The plugin, Page Lists Plus, lets you (among other things) link to a Page in Page lists using something other than its title as the link text (e.g. you could shorten the link to your “Frequently Asked Questions” page to “FAQ”). Not what you’re trying to do.
Hey Tim, thanks! — looking at it now — not obvious to me (sorry). I thought that the “change permalink” at the top of editing a page would let me do that(a long time ago), but it seemed to just go into “choose how to automatically name pages” – which is not what I wanted — just wanted, for instance, to name THIS one page. Reading through “using permalinks”, I still don’t see how to do that. And the closest I came, I think was “this is discouraged, but you can use %postname%”…
So, let’s just pretend <ahem> that I’m real stupid and could you spell out how I would actually change a single page name? Say it is currently ?page=23 and I want it to be lessonlist.html. How would I do that?
I’m on linux, btw. thx! — Joe B.
Set your permalinks to %postname%. On the edit screen for each page, underneath the title box, you’ll then see a box that lets you edit that page’s url.
If you want “.html” at the end of your urls then you’ll need a plugin, because of the period. I’ve used (the misnamed) Periods in Titles for this before. Advanced Permalinks is more recent and more feature-rich, so might be worth a look too.
- The topic ‘Getting wp_list_pages to output page name instead of page title’ is closed to new replies.