The problem, as I could see it, is not with the get_the_category()
function. Instead, it’s the way you output the category archive link: href="<?php echo $cd->slug ?>"
— you should instead use get_category_link()
to get the correct URL of the category archive page. Example:
<a href="<?php echo esc_url( get_category_link( $cd ) ); ?>">