| 67 | * Will attempt to retrieve templates specific to the query vars that are |
| 68 | * present in the URL returning a 404 error. For example, if the tag query |
| 69 | * var is set, 404-tag.php and 404-archive.php will be returned in addition |
| 70 | * to the default 404.php. |
| 71 | * |
| 72 | * Works by looping through the '$checks' array and checking to see if each |
| 73 | * query var is set. If one is, the template slugs for that query var will be |
| 74 | * looped through to build the template filenames. |
| 75 | * |
77 | | return get_query_template('404'); |
| 86 | |
| 87 | $checks = array( |
| 88 | 'taxonomy' => array( 'taxonomy-%s', 'taxonomy', 'archive' ), |
| 89 | 'attachment' => array( 'attachment', 'single', 'singular' ), |
| 90 | 'attachment_id' => array( 'attachment', 'single', 'singular' ), |
| 91 | 'post_type' => array( 'single-%s', 'single', 'singular' ), |
| 92 | 'p' => array( 'single', 'singular' ), |
| 93 | 'name' => array( 'single', 'singular' ), |
| 94 | 'page_id' => array( 'page', 'singular' ), |
| 95 | 'cat' => array( 'category', 'archive' ), |
| 96 | 'category_name' => array( 'category', 'archive' ), |
| 97 | 'tag' => array( 'tag', 'archive' ), |
| 98 | 'author' => array( 'author', 'archive' ), |
| 99 | 'm' => array( 'date', 'archive' ), |
| 100 | 'year' => array( 'date', 'archive' ), |
| 101 | 'monthnum' => array( 'date', 'archive' ), |
| 102 | 'day' => array( 'date', 'archive' ), |
| 103 | ); |
| 104 | |
| 105 | $templates = array(); |
| 106 | |
| 107 | foreach ( $checks as $query_var => $template_slugs ) { |
| 108 | if ( $query_var = get_query_var( $query_var ) ) { |
| 109 | foreach ( $template_slugs as $template_slug ) { |
| 110 | $templates[] = '404-' . sprintf( $template_slug, $query_var ) . '.php'; |
| 111 | } |
| 112 | break; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | $templates[] = '404.php'; |
| 117 | |
| 118 | return get_query_template( '404', $templates ); |