Extract categories html to a function