WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 3 months ago

#9719 closed feature request (duplicate)

Please : a filter for $category object in get_the_category_list()

Reported by: michelwppi Owned by:
Milestone: Priority: normal
Severity: minor Version: 2.8
Component: Template Keywords: needs-patch
Focuses: Cc:

Description

To offer for one post more flexibility in how to display the names of categories in the_category() or in get_the_category_list() -file category-template line 166 - , is it possible to add a filter as the filter existing in wp_list_categories() . Useful to replace cat name by instance by image (iphone compatible theme) or to add translation in bilingual or multilingual theme (by instance with xili-language plugin) without re-creating specific function.

As in classes.php (line 1328), I suggest this modif with a filter named post_list_cats for the start of two loops present in get_the_category_list() (line 187 et 209)

foreach ( $categories as $category ) {
$cat_name = attr( $category->name);
$cat_name = apply_filters( 'post_list_cats', $cat_name, $category );

and inside the two loops, $category->cat_name replaced by $cat_name

with this filter it will be more coherent to treate cat list in one post or in sidebar for all posts

Many thanks

Change History (11)

comment:1 Denis-de-Bernardy5 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

there are a ticket or two in the 2.8 milestone already, that ask for the category list to be filtered, raw, before it gets turned into html. closing this as dup of those.

comment:2 Denis-de-Bernardy5 years ago

please reopen if you had something else in mind, though.

comment:3 michelwppi5 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

What are the ticket number talking about this subject ? Thanks

comment:4 Denis-de-Bernardy5 years ago

  • Milestone set to 2.8

things like #8704

please re-close as dup if it does the trick

comment:5 michelwppi5 years ago

in trac #8704 the proposed filter is placed upstream and will it be able to place an image url in place of a simple category name? the hook 8704 while large impact in what I propose, only the category (terms) in question. Is my english understandable ?

comment:7 michelwppi5 years ago

  • Cc michelwppi added
  • Summary changed from Please : a filter for $category name in get_the_category_list() to Please : a filter for $category object in get_the_category_list()

this ticket #9227 is much more relevant and adapted to the desired functional. Even if wp_list_categories(), a filter exists for each three parts of one element (name, link, and description). Here, just with adding a line like below, the potentialities of adaption are huge :

As in classes.php (line 1328), I suggest this adapted modif with a filter named post_list_cats for the start of two loops present in get_the_category_list() (line 187 et 209)

foreach ( $categories as $category ) {
$category = apply_filters( 'post_list_cats', $category);

If, as asked in the cited trac, the echo (display) is added in the function get_the_category_list() (with modif inside the_category), a second param 'echo' can be passed in this filter.

Hope this modif will be implemented soon, to built easy plug and play kit to transform automatically a well made theme in a theme for iPhone or a multilingual theme (without coding by the bloger).

comment:8 Denis-de-Bernardy5 years ago

  • Component changed from General to Template
  • Keywords needs-patch added
  • Priority changed from high to normal
  • Severity changed from normal to minor

#8704 got fixed. Might we want to close this as fixed along with it?

comment:9 Denis-de-Bernardy5 years ago

  • Milestone changed from 2.8 to 2.9

Punting per discussion during the WP meet-up...

comment:10 Denis-de-Bernardy5 years ago

  • Milestone changed from 2.9 to Future Release

comment:11 johnbillion3 months ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from reopened to closed

Duplicate of #8704.

Note: See TracTickets for help on using tickets.