Make WordPress Core


Ignore:
Timestamp:
04/24/2015 02:56:37 PM (9 years ago)
Author:
boonebgorges
Message:

In wp_list_categories(), 'All' link should point to post type archive if taxonomy is not registered for 'post' or 'page'.

Instead, we point to the post type archive of the first registered
object_type that supports archives.

Props stevegrunwell, hrishiv90, boonebgorges.
Fixes #21881.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/category-template.php

    r32026 r32292  
    533533    } else {
    534534        if ( ! empty( $show_option_all ) ) {
    535             $posts_page = ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' );
     535
     536            $posts_page = '';
     537
     538            // For taxonomies that belong only to custom post types, point to a valid archive.
     539            $taxonomy_object = get_taxonomy( $r['taxonomy'] );
     540            if ( ! in_array( 'post', $taxonomy_object->object_type ) && ! in_array( 'page', $taxonomy_object->object_type ) ) {
     541                foreach ( $taxonomy_object->object_type as $object_type ) {
     542                    $_object_type = get_post_type_object( $object_type );
     543
     544                    // Grab the first one.
     545                    if ( ! empty( $_object_type->has_archive ) ) {
     546                        $posts_page = get_post_type_archive_link( $object_type );
     547                        break;
     548                    }
     549                }
     550            }
     551
     552            // Fallback for the 'All' link is the front page.
     553            if ( ! $posts_page ) {
     554                $posts_page = 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' );
     555            }
     556
    536557            $posts_page = esc_url( $posts_page );
    537558            if ( 'list' == $r['style'] ) {
Note: See TracChangeset for help on using the changeset viewer.