Add category slug as class attribute in a link array

Ok guys found the solution myself (5 days later, oof) added below to help someone else in the future…

foreach((get_the_category( $related_post->ID )) as $category) {                             
    $output .= "<a class=\"$category->slug\"  href=\"".get_permalink( $related_post->ID )."\" title=\"" . $category->cat_name . "\">" . $category->cat_name . "</a>";
}

Basically the old link above looked like this…

$output .= "<a href=\"".get_permalink( $related_post->ID )."\">".$related_post->post_title."</a>";

I took the link and added it in a foreach loop of it’s own. Then I prepared the foundations by calling the get_the_category for the related_post by it’s ID. That then gave me access to everything that the $category hook in WP offer, so I then simply call $category->cat_name for the category name and in turn $category->slug for the category slug name.

How cool is WP, VERY COOL!!! Anyway hope this help somebody out there.