Ticket #4004 (new enhancement)

Opened 2 years ago

Last modified 7 months ago

New filter for page title attribute in wp_list_pages output

Reported by: Dickie Assigned to: ryan
Priority: normal Milestone: 2.9
Component: Template Version: 2.1.3
Severity: normal Keywords: filter wp_list_pages has-patch
Cc: westi

Description

While developing a new theme I realised that the default title attribute for wp_list_pages was to just to reuse the title of the page with no option to change it. Not exactly useful...

I therefore propose a new filter on the title attribute to allow a theme/plugin developer the option of changing the text to whatever they like.

The new filter takes the title attribute and the $page variable as well, so that any post/page related information can also be used... for example the post meta.

Attachments

Filter change.patch (0.8 kB) - added by Dickie on 03/20/07 22:45:44.
Patch File for Filter Change
4004.diff (0.8 kB) - added by rob1n on 03/30/07 23:12:31.
A different, Page_Walker-based filter name.
Filter change-02.patch (1.0 kB) - added by Dickie on 04/03/07 23:00:40.
Updated to included latest trunk filters.

Change History

03/20/07 22:45:44 changed by Dickie

  • attachment Filter change.patch added.

Patch File for Filter Change

03/20/07 23:10:53 changed by Dickie

  • keywords changed from filter wp_list_pages to filter wp_list_pages has-patch.

03/27/07 21:31:33 changed by westi

  • keywords changed from filter wp_list_pages has-patch to filter wp_list_pages has-patch commit.
  • owner changed from anonymous to ryan.
  • summary changed from New filter for page title attribute to New filter for page title attribute in wp_list_pages output.
  • milestone changed from 2.1.3 to 2.2.

+1

My only question is regarding the naming of the filter as it is being called from within the Page_Walker class - maybe it should reference that instead.

03/28/07 21:32:45 changed by westi

  • cc set to westi.

03/30/07 23:12:31 changed by rob1n

  • attachment 4004.diff added.

A different, Page_Walker-based filter name.

03/30/07 23:45:55 changed by Dickie

I am interested to know why have you decided to remove the $page attribute added to the filter. Surely this is useful for plugin developers to get more info about this post, as just passing in the title gives no extra information.

03/31/07 10:09:06 changed by westi

I agree with Dickie here. We need to pass $page through to the filter otherwise it is pretty useless as it has no other context.

If a plugin author wanted to use this filter they need some context to work with.

(follow-ups: ↓ 7 ↓ 9 ) 04/01/07 19:38:18 changed by rob1n

In the trunk we now run it through the_title, both on the attribute and the page title.

(in reply to: ↑ 6 ) 04/01/07 20:36:48 changed by westi

Replying to rob1n:

In the trunk we now run it through the_title, both on the attribute and the page title.

I don't think that helps much.

How can we tell the context of the call? i.e. attribute/content.

I agree adding the the_title filter to the title when used as content makes sense.

I feel we still need a new filter for when it is the title attribute - and we still need to pass the post object through for anyone that wants it here as they can't easily get the context in any other way as posts titles are not unique.

04/02/07 21:59:09 changed by Dickie

Just to give some context to this.

For example... I set the page title to be "About" but when the visitor to my website hovers over the link in the menu bar for the About page I do not want it to say "About" but perhaps "Visit my about page" or "Go to the page with information about me", this could either be hard coded in the plug-in (not good perhaps) or gleaned from the page meta data, or a mixture of both. The point is, I need different text for both the Page name itself AND the page title attribute. The way it was working in the supplied patch file was fine, the only issue I could see was the name of the filter itself (and to be honest I was not sure about that as it was not directly in wp_list_pages, but I went with it anyway as it seemed the most logical)

04/03/07 23:00:40 changed by Dickie

  • attachment Filter change-02.patch added.

Updated to included latest trunk filters.

(in reply to: ↑ 6 ) 04/03/07 23:08:27 changed by Dickie

Replying to rob1n:

In the trunk we now run it through the_title, both on the attribute and the page title.

In this patch I have also taken to opportunity to only run "the_title" filter once (as it was being run twice), then run the result of that filter through the attribute title filter "walker_page_title".

04/04/07 22:11:27 changed by Dickie

I am not sure about my last patch now, if we really must pass the title Attribute through "the_title" filter, then the attribute filter should go second. (like this)

// As the post title is needed in two places, rather than process the filter twice, store it in $title
$title = apply_filters('the_title', $page->post_title);
// The title will also be run through another filter to determine the title attribute for the link
$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('walker_page_title',$title, $page)) . '">' . $title . '</a>';

But I cant help feeling that this is a bad idea... the anchor title attribute is a label for the link, and as such is likely to be completely different from the Title of the post itself. therefore I think that this solution is the better one, which is more similar to my first patch before the "the_title" filters were added

$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('walker_page_title',$page->post_title, $page)) . '">' . apply_filters('the_title', $page->post_title) . '</a>';

Also, I still feel strongly and agree with westi on this, that the $page var needs to be sent to the filter to give it some context.

04/12/07 18:15:51 changed by foolswisdom

  • milestone changed from 2.2 to 2.3.

05/01/07 13:31:39 changed by rob1n

  • keywords changed from filter wp_list_pages has-patch commit to filter wp_list_pages has-patch.

09/13/07 21:19:39 changed by ryan

  • milestone changed from 2.3 to 2.4.

09/14/07 07:51:14 changed by westi

Relates to #4893

03/14/08 09:31:21 changed by Denis-de-Bernardy

03/19/08 03:47:52 changed by ffemtcj

  • milestone changed from 2.5 to 2.6.