This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: How to display post's category on related posts

#7161
Ernest MarcinkoErnest Marcinko
Keymaster

Hi!

I think a better solution would be to use a filtering function, so the source code is not changed and it’s update proof.

I’ve put together a function that might do the trick. Put this to the functions.php file in your active theme directory:

[php]add_filter( ‘rpp_item_after_postprocessing’, ‘rpp_add_category_titles’, 1, 1 );

function rpp_add_category_titles( $post ) {

// Get the post categories
$post_categories = wp_get_post_categories( $post->ID );
$cats = "";

// Concatenate category names to the $cats variable
foreach($post_categories as $c){
$cat = get_category( $c );
$cats .= " ".$cat->name;
}

if ( $cats != "")
$post->author = $cats;

return $post;
}[/php]

Make sure to save the related posts pro options to clear the posts cache.

I haven’t tried this code, but I’m hoping it will work.