you need to take different post types into account. This covers at least three types, but probably also custom types. Still need to change the template according to the type