WordPress.org

Make WordPress Core

Changeset 15819


Ignore:
Timestamp:
10/15/10 19:44:57 (4 years ago)
Author:
nacin
Message:

Custom post type archives, second pass. see #13818.

Location:
trunk/wp-includes
Files:
5 edited

Legend:

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

    r15771 r15819  
    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) ) { 
     
    612616 * 
    613617 * @since 0.71 
    614  * @uses $wpdb 
    615618 * 
    616619 * @param string $prefix Optional. What to display before the title. 
     
    636639} 
    637640 
     641/** 
     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     
    638667/** 
    639668 * Display or retrieve page title for category archive. 
  • trunk/wp-includes/link-template.php

    r15817 r15819  
    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; 
     
    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 * 
  • trunk/wp-includes/post-template.php

    r15651 r15819  
    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'; 
     
    473476        elseif ( is_search() ) 
    474477            $classes[] = 'search-paged-' . $page; 
     478        elseif ( is_post_type_archive() ) 
     479            $classes[] = 'post-type-paged-' . $page; 
    475480    } 
    476481 
  • trunk/wp-includes/post.php

    r15806 r15819  
    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 ) 
  • trunk/wp-includes/query.php

    r15803 r15819  
    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 * 
     
    10401056     */ 
    10411057    var $is_posts_page = false; 
     1058 
     1059    /** 
     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; 
    10421067 
    10431068    /** 
     
    10761101        $this->is_robots = false; 
    10771102        $this->is_posts_page = false; 
     1103        $this->is_post_type_archive = false; 
    10781104    } 
    10791105 
     
    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']) ) { 
     
    13071333                $this->is_author = true; 
    13081334 
    1309             if ( !empty( $qv['post_type'] ) ) 
    1310                 $this->is_archive = true; 
    1311  
    1312             if ( $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax ) 
     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            } 
     1340 
     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        } 
     
    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     * 
Note: See TracChangeset for help on using the changeset viewer.