In your functions.php, you can filter the_category_list
, which is an array of categories for a post.
function wpse_the_category_list( $categories, $post_id ) {
return array_slice( $categories, 0, 2, true );
}
add_filter( 'the_category_list', 'wpse_the_category_list', 10, 2 );
And then display the categories in your template file with:
the_category();