Adding a check for custom taxonomies on archive pages.
On search and archive pages there isn’t a specific archive_<post_type>.php yet so you have to edit your current archive and search to compensate for it being used for custom post types and taxonomies. On a good note, there is the $wp_query->query_vars that we can work with. (if) there is a custom post type taxonomy being set it will be in those variables. Now here’s the interesting part. If we check for the is_category() and is_tag() ahead of the check for the query_var checks it will weed out the normal post post_type from the ones in custom post types.
<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?> <?php /* Category Archive */ if (is_category()) { ?> <h2 class="pagetitle"><?php _e('Archive for ‘','comicpress'); ?><?php single_cat_title() ?>’</h2> <?php /* Tag Archive */ } elseif( is_tag() ) { ?> <h2 class="pagetitle"><?php _e('Posts Tagged ‘','comicpress'); ?><?php single_tag_title() ?>’</h2> <?php /* Daily Archive */ } elseif (is_day()) { ?> <h2 class="pagetitle"><?php _e('Archive for','comicpress'); ?> <?php the_time('F jS, Y') ?></h2> <?php /* Monthly Archive */ } elseif (is_month()) { ?> <h2 class="pagetitle"><?php _e('Archive for','comicpress'); ?> <?php the_time('F, Y') ?></h2> <?php /* Yearly Archive */ } elseif (is_year()) { ?> <h2 class="pagetitle"><?php _e('Archive for','comicpress'); ?> <?php the_time('Y') ?></h2> <?php /* Author Archive */ } elseif (is_author()) { ?> <h2 class="pagetitle"><?php _e('Author Archive','comicpress'); ?></h2> <?php /* Paged Archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?> <h2 class="pagetitle"><?php _e('Archives','comicpress'); ?></h2> <?php /* taxonomy */ } elseif (is_taxonomy($wp_query->query_vars['taxonomy'])) { if (is_term($wp_query->query_vars['term'])) { ?> <h2 class="pagetitle"><?php echo $wp_query->query_vars['taxonomy']; ?> - <?php echo $wp_query->query_vars['term']; ?></h2> <?php } else { ?> <h2 class="pagetitle"><?php echo $wp_query->query_vars['taxonomy']; ?></h2> <?php } ?> <?php /* Post Type */ } elseif ($post->post_type !== 'post') { ?> <h2 class="pagetitle"><?php echo $post->post_type; ?></h2> <?php } ?>
I know this isn’t pretty and if anyone wants to rewrite it to be a little cleaner I would be grateful for that. There also needs to be a fix for the different [pages] that occur with pagination.
– Phil
Discussion ¬