Advertisement
keha76

Taxonomy Term Archive - Rewrite and include template file

Jan 29th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. <?php
  2.  
  3. function taxonomy_term_archve_rewrite_rules() {
  4.     add_rewrite_rule( '(.+)/?$', 'index.php?taxonomy=$matches[1]', 'top' );
  5. }
  6. add_action( 'init', 'taxonomy_term_archve_rewrite_rules' );
  7.  
  8. function taxonomy_term_archive_template( $template ) {
  9.  
  10.     global $wp_query;
  11.  
  12.     // Check if the query_var taxonomy is set
  13.     if ( isset( $wp_query->query_vars['taxonomy'] ) ) {
  14.    
  15.         // Custom template file in my theme
  16.         $taxonomy_term_archive_template = TEMPLATEPATH . '/templates/taxonomy-term-archive.php';
  17.  
  18.         // Return the template file
  19.         if ( file_exists( $taxonomy_term_archive_template ) ) {
  20.             $file_headers = @get_headers( $taxonomy_term_archive_template );
  21.             if ( $file_headers[0] != 'HTTP/1.0 404 Not Found' ) {
  22.                 return $taxonomy_term_archive_template;
  23.             }
  24.         }
  25.     }
  26.     return $template;
  27. }
  28. add_filter( 'template_include', 'taxonomy_term_archive_template' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement