views:

30

answers:

1

I would like that the RSS entries titles be like this:

"this is the post title [category1, category4]"

In square brackets are listed the categories in which the post is filed.

I first modified the wp-feed.php file, but it's dirty: every wordpress update will erase my changes. So i think i can do this via add_filter. I set it up like this, but i don't know how i can have access to the post categories within my function. Any idea?

  function rssTitle_add_categories($title) {
        // how do i retrieve the category array ?
        $categories = join(', ', $category_array);
        $title = $title . '['.$categories.']';
        return $title;
    }
    add_filter('the_title_rss', 'rssTitle_add_categories');
+1  A: 

When the_title_rss filter functions are called (from the feed templates) you are inside a Wordpress posts loop, and so the usual functions should work. You should be able to do something like this:

$category_array = array_map(create_function('$category', 'return $category->name;'), get_the_category());
$categories = join(', ', $category_array);
$title = $title . '['.$categories.']';
return $title;
Richard M
Works perfectly, thanks a lot!
pixeline