Make WordPress Core

Ticket #21881: 21881.3.patch

File 21881.3.patch, 1.5 KB (added by stevegrunwell, 10 years ago)

Talking it through with Nacin, we realized that changing the "all" link based on context was the wrong behavior. Instead, if a post type is only used for one, non-built-in taxonomy, link to the archive for that post type (if it exists).

  • src/wp-includes/category-template.php

     
    511511                }
    512512        } else {
    513513                if ( ! empty( $show_option_all ) ) {
    514                         $posts_page = ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' );
     514
     515                        /*
     516                         * If the taxonomy is exclusive to one post type (not posts/pages) *and* an archive for that post type exists,
     517                         * link to the post type archive instead of home
     518                         */
     519                        $taxonomy_object = get_taxonomy( $r['taxonomy'] );
     520                        $link_to_post_type_archive = false;
     521                        if ( 1 === count( $taxonomy_object->object_type ) && ! in_array( $taxonomy_object->object_type['0'], array( 'post', 'page' ) ) ) {
     522                                $tax_post_type = get_post_type_object( $taxonomy_object->object_type['0'] );
     523                                $link_to_post_type_archive = (bool) $tax_post_type->has_archive;
     524                        }
     525
     526                        if ( $link_to_post_type_archive ) {
     527                                $posts_page = get_post_type_archive_link( $taxonomy_object->object_type['0'] );
     528                        } elseif ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) {
     529                                $posts_page = get_permalink( get_option( 'page_for_posts' ) );
     530                        } else {
     531                                $posts_page = home_url( '/' );
     532                        }
    515533                        $posts_page = esc_url( $posts_page );
    516534                        if ( 'list' == $r['style'] ) {
    517535                                $output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>";