Reduce duplicate code in categories views.