WordPress.org

Make WordPress Core

Ticket #13818: 13818.2.diff

File 13818.2.diff, 8.5 KB (added by nacin, 8 years ago)

(refreshed for minor fixes)

  • wp-includes/post-template.php

     
    407407                        $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
    408408                }
    409409        } elseif ( is_archive() ) {
    410                 if ( is_author() ) {
     410                if ( is_post_type_archive() ) {
     411                        $classes[] = 'post-type-archive';
     412                        $classes[] = 'post-type-archive-' . sanitize_html_class( get_query_var( 'post_type' ) );
     413                } else if ( is_author() ) {
    411414                        $author = $wp_query->get_queried_object();
    412415                        $classes[] = 'author';
    413416                        $classes[] = 'author-' . sanitize_html_class( $author->user_nicename , $author->ID );
     
    472475                        $classes[] = 'author-paged-' . $page;
    473476                elseif ( is_search() )
    474477                        $classes[] = 'search-paged-' . $page;
     478                elseif ( is_post_type_archive() )
     479                        $classes[] = 'post-type-paged-' . $page;
    475480        }
    476481
    477482        if ( !empty( $class ) ) {
  • wp-includes/post.php

     
    924924                if ( !isset($args->rewrite['archive']) )
    925925                        $args->rewrite['archive'] = false;
    926926                if ( !isset($args->rewrite['feeds']) || !$args->rewrite['archive'] )
    927                         $args->rewrite['feeds'] = false;
     927                        $args->rewrite['feeds'] = (bool) $args->rewrite['archive'];
    928928
    929929                if ( $args->hierarchical )
    930930                        $wp_rewrite->add_rewrite_tag("%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");
  • wp-includes/query.php

     
    121121}
    122122
    123123/**
     124 * Is the query for a post type archive page?
     125 *
     126 * @see WP_Query::is_post_type_archive()
     127 * @since 3.1.0
     128 * @uses $wp_query
     129 *
     130 * @param mixed $post_types Optional. Post type or array of posts types to check against.
     131 * @return bool
     132 */
     133function is_post_type_archive( $post_types = '' ) {
     134        global $wp_query;
     135
     136        return $wp_query->is_post_type_archive( $post_types );
     137}
     138       
     139/**
    124140 * Is the query for an attachment page?
    125141 *
    126142 * @see WP_Query::is_attachment()
     
    10411057        var $is_posts_page = false;
    10421058
    10431059        /**
     1060         * Set if query is for a post type archive.
     1061         *
     1062         * @since 3.1.0
     1063         * @access public
     1064         * @var bool
     1065         */
     1066        var $is_post_type_archive = false;
     1067
     1068        /**
    10441069         * Resets query flags to false.
    10451070         *
    10461071         * The query flags are what page info WordPress was able to figure out.
     
    10751100                $this->is_singular = false;
    10761101                $this->is_robots = false;
    10771102                $this->is_posts_page = false;
     1103                $this->is_post_type_archive = false;
    10781104        }
    10791105
    10801106        /**
     
    12341260                        $this->is_page = true;
    12351261                        $this->is_single = false;
    12361262                } else {
    1237                 // Look for archive queries.  Dates, categories, authors, search.
     1263                // Look for archive queries.  Dates, categories, authors, search, post type archives.
    12381264
    12391265                        if ( !empty($qv['s']) ) {
    12401266                                $this->is_search = true;
     
    13061332                        if ( '' != $qv['author_name'] )
    13071333                                $this->is_author = true;
    13081334
    1309                         if ( !empty( $qv['post_type'] ) )
    1310                                 $this->is_archive = true;
     1335                        if ( !empty( $qv['post_type'] ) && ! is_array( $qv['post_type'] ) ) {
     1336                                $post_type_obj = get_post_type_object( $qv['post_type'] );
     1337                                if ( is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['archive'] )
     1338                                        $this->is_post_type_archive = true;
     1339                        }
    13111340
    1312                         if ( $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax )
     1341                        if ( $this->is_post_type_archive || $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax )
    13131342                                $this->is_archive = true;
    13141343                }
    13151344
     
    26362665        }
    26372666
    26382667        /**
     2668         * Is the query for a post type archive page?
     2669         *
     2670         * @since 3.1.0
     2671         *
     2672         * @param mixed $post_types Optional. Post type or array of posts types to check against.
     2673         * @return bool
     2674         */
     2675        function is_post_type_archive( $post_types = '' ) {
     2676                if ( empty( $post_types ) || !$this->is_post_type_archive )
     2677                        return (bool) $this->is_post_type_archive;
     2678
     2679                if ( ! isset( $this->posts[0] ) )
     2680                        return false;
     2681
     2682                $post = $this->posts[0];
     2683
     2684                return in_array( $post->post_type, (array) $post_types );
     2685        }
     2686
     2687        /**
    26392688         * Is the query for an attachment page?
    26402689         *
    26412690         * @since 3.1.0
  • wp-includes/link-template.php

     
    3939                $string = untrailingslashit($string);
    4040
    4141        // Note that $type_of_url can be one of following:
    42         // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged
     42        // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged, post_type_archive
    4343        $string = apply_filters('user_trailingslashit', $string, $type_of_url);
    4444        return $string;
    4545}
     
    825825}
    826826
    827827/**
     828 * Retrieve the permalink for a post type archive.
     829 *
     830 * @since 3.1.0
     831 *
     832 * @param string $post_type Post type
     833 * @return string
     834 */
     835function get_post_type_archive_link( $post_type ) {
     836        global $wp_rewrite;
     837        if ( ! $post_type_obj = get_post_type_object( $post_type ) )
     838                return false;
     839
     840        if ( ! is_array( $post_type_obj->rewrite ) || false === $post_type_obj->rewrite['archive'] )
     841                return false;
     842
     843        if ( get_option( 'permalink_structure' ) ) {
     844                $struct = ( true === $post_type_obj->rewrite['archive'] ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->rewrite['archive'];
     845                if ( $post_type_obj->rewrite['with_front'] )
     846                        $struct = $wp_rewrite->front . $struct;
     847                $link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) );
     848        } else {
     849                $link = home_url( '?post_type=' . $post_type );
     850        }
     851
     852        return apply_filters( 'post_type_archive_link', $link, $post_type );
     853}
     854
     855/**
     856 * Retrieve the permalink for a post type archive feed.
     857 *
     858 * @since 3.1.0
     859 *
     860 * @param string $post_type Post type
     861 * @param string $feed Optional. Feed type
     862 * @return string
     863 */     
     864function get_post_type_archive_feed_link( $post_type, $feed = '' ) {
     865        $default_feed = get_default_feed();
     866        if ( empty( $feed ) )
     867                $feed = $default_feed;
     868
     869        if ( ! $link = get_post_type_archive_link( $post_type ) )
     870                return false;
     871        $post_type_obj = get_post_type_object( $post_type );
     872        if ( $post_type_obj->rewrite['feeds'] && get_option( 'permalink_structure' ) ) {
     873                $link = trailingslashit($link);
     874                $link .= 'feed/';
     875                if ( $feed != $default_feed )
     876                        $link .= "$feed/";
     877        } else {
     878                $link = add_query_arg( 'feed', $feed, $link );
     879        }
     880
     881        return apply_filters( 'post_type_archive_feed_link', $link, $feed );
     882}
     883
     884/**
    828885 * Retrieve edit posts link for post.
    829886 *
    830887 * Can be used within the WordPress loop or outside of it. Can be used with
  • wp-includes/general-template.php

     
    547547                $title = $author->display_name;
    548548        }
    549549
     550        // If there's a post type archive
     551        if ( is_post_type_archive() )
     552                $title = post_type_archive_title( '', false );
     553
    550554        // If there's a month
    551555        if ( is_archive() && !empty($m) ) {
    552556                $my_year = substr($m, 0, 4);
     
    611615 * be a space, the parameter value will need to have it at the end.
    612616 *
    613617 * @since 0.71
    614  * @uses $wpdb
    615618 *
    616619 * @param string $prefix Optional. What to display before the title.
    617620 * @param bool $display Optional, default is true. Whether to display or retrieve title.
     
    636639}
    637640
    638641/**
     642 * Display or retrieve title for a post type archive.
     643 *
     644 * This is optimized for archive.php and archive-{$post_type}.php template files
     645 * for displaying the title of the post type.
     646 *
     647 * @since 3.1.0
     648 *
     649 * @param string $prefix Optional. What to display before the title.
     650 * @param bool $display Optional, default is true. Whether to display or retrieve title.
     651 * @return string|null Title when retrieving, null when displaying or failure.
     652 */
     653function post_type_archive_title() {
     654        if ( ! is_post_type_archive() )
     655                return;
     656
     657       
     658        $post_type_obj = get_post_type_object( get_query_var( 'post_type' ) );
     659        $title = apply_filters('post_type_archive_title', $post_type_obj->labels->name );
     660
     661        if ( $display )
     662                echo $prefix . $title;
     663        else
     664                return $title;
     665}
     666       
     667/**
    639668 * Display or retrieve page title for category archive.
    640669 *
    641670 * This is useful for category template file or files, because it is optimized