WordPress.org

Make WordPress Core

Ticket #21881: 21881.4.patch

File 21881.4.patch, 2.3 KB (added by hrishiv90, 7 years ago)

Updated patch as suggested by @boonebgorges

  • category-template.php

    # This patch file was generated by NetBeans IDE
    # Following Index: paths are relative to: /home/hrishikesh/Projects/wp/trunk/wp-includes
    # This patch can be applied using context Tools: Patch action on respective folder.
    # It uses platform neutral UTF-8 encoding and \n newlines.
    # Above lines and this line are ignored by the patching process.
     
    532532                }
    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                        /*
     537                         * If the taxonomy is exclusive to one post type (not posts/pages) *and* an archive for that post type exists,
     538                         * link to the post type archive instead of home
     539                         */
     540                        $taxonomy_object = get_taxonomy( $r['taxonomy'] );
     541                        $link_to_post_type_archive = false;
     542                        $taxonomy_object_type = $taxonomy_object->object_type;
     543                        while ( !$link_to_post_type_archive && count($taxonomy_object_type) > 0 ) {
     544                            $object_type = array_shift($taxonomy_object_type);
     545                            if ( ! in_array( $object_type, array( 'post', 'page' ) ) ) {
     546                                $tax_post_type = get_post_type_object( $object_type );
     547                                $link_to_post_type_archive = (bool) $tax_post_type->has_archive;
     548                            } else {
     549                                $taxonomy_object_type = array();
     550                            }
     551                        }
     552
     553                        if ( $link_to_post_type_archive ) {
     554                                $posts_page = get_post_type_archive_link( $object_type );
     555                        } elseif ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) {
     556                                $posts_page = get_permalink( get_option( 'page_for_posts' ) );
     557                        } else {
     558                                $posts_page = home_url( '/' );
     559                        }
    536560                        $posts_page = esc_url( $posts_page );
    537561                        if ( 'list' == $r['style'] ) {
    538562                                $output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>";