Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template Hierarchy: Extend to include root taxonomy archives #3

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/wp-includes/class-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -3871,6 +3871,7 @@ public function query( $query ) {
* query variable. After it is set up, it will be returned.
*
* @since 1.5.0
* @since 6.8.0 Return the queried taxonomy object for taxonomy queries if no term is specified.
*
* @return WP_Term|WP_Post_Type|WP_Post|WP_User|null The queried object.
*/
Expand Down Expand Up @@ -3925,6 +3926,9 @@ public function get_queried_object() {
if ( $this->is_category && 'category' === $this->queried_object->taxonomy ) {
_make_cat_compat( $this->queried_object );
}
} else {
// If no term is specified, return the queried taxonomy object instead.
return get_taxonomy( $matched_taxonomy );
}
} elseif ( $this->is_post_type_archive ) {
$post_type = $this->get( 'post_type' );
Expand Down
5 changes: 4 additions & 1 deletion src/wp-includes/general-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -1760,14 +1760,17 @@ function get_the_archive_title() {
$prefix = _x( 'Archives:', 'post type archive title prefix' );
} elseif ( is_tax() ) {
$queried_object = get_queried_object();
if ( $queried_object ) {
if ( $queried_object instanceof WP_Term ) {
$tax = get_taxonomy( $queried_object->taxonomy );
$title = single_term_title( '', false );
$prefix = sprintf(
/* translators: %s: Taxonomy singular name. */
_x( '%s:', 'taxonomy term archive title prefix' ),
$tax->labels->singular_name
);
} elseif ( $queried_object instanceof WP_Taxonomy ) {
$title = $queried_object->labels->singular_name;
$prefix = _x( 'Archives:', 'taxonomy archive title prefix' );
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/wp-includes/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,12 @@ function get_tag_template() {
* @return string Full path to custom taxonomy term template file.
*/
function get_taxonomy_template() {
$term = get_queried_object();
$term_or_tax = get_queried_object();

$templates = array();

if ( ! empty( $term->slug ) ) {
if ( $term_or_tax instanceof WP_Term && ! empty( $term_or_tax->slug ) ) {
$term = $term_or_tax;
$taxonomy = $term->taxonomy;

$slug_decoded = urldecode( $term->slug );
Expand All @@ -358,6 +359,9 @@ function get_taxonomy_template() {

$templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
$templates[] = "taxonomy-$taxonomy.php";
} elseif ( $term_or_tax instanceof WP_Taxonomy ) {
$taxonomy = $term_or_tax->name;
$templates[] = "taxonomy-$taxonomy.php";
}
$templates[] = 'taxonomy.php';

Expand Down