Changeset 25291
- Timestamp:
- 09/06/2013 10:06:40 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/general-template.php
r25207 r25291 578 578 } 579 579 580 // If there's a post type archive 581 if ( is_post_type_archive() ) { 582 $post_type_object = get_post_type_object( get_query_var( 'post_type' ) ); 583 if ( ! $post_type_object->has_archive ) 584 $title = post_type_archive_title( '', false ); 585 } 586 580 587 // If there's a category or tag 581 588 if ( is_category() || is_tag() ) { … … 596 603 } 597 604 598 // If there's a post type archive599 if ( is_post_type_archive() )605 // Post type archives with has_archive should override terms. 606 if ( is_post_type_archive() && $post_type_object->has_archive ) 600 607 $title = post_type_archive_title( '', false ); 601 608 … … 697 704 return; 698 705 699 $post_type_obj = get_ queried_object();706 $post_type_obj = get_post_type_object( get_query_var( 'post_type' ) ); 700 707 $title = apply_filters('post_type_archive_title', $post_type_obj->labels->name ); 701 708 … … 1671 1678 $args = wp_parse_args( $args, $defaults ); 1672 1679 1673 if ( is_sing le() || is_page() ) {1680 if ( is_singular() ) { 1674 1681 $id = 0; 1675 1682 $post = get_post( $id ); … … 1679 1686 $href = get_post_comments_feed_link( $post->ID ); 1680 1687 } 1688 } elseif ( is_post_type_archive() ) { 1689 $post_type_obj = get_post_type_object( get_query_var( 'post_type' ) ); 1690 $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name ); 1691 $href = get_post_type_archive_feed_link( $post_type_obj->name ); 1681 1692 } elseif ( is_category() ) { 1682 1693 $term = get_queried_object(); -
trunk/src/wp-includes/query.php
r25289 r25291 3148 3148 */ 3149 3149 function is_post_type_archive( $post_types = '' ) { 3150 if ( empty( $post_types ) || ! $this->is_post_type_archive )3150 if ( empty( $post_types ) || ! $this->is_post_type_archive ) 3151 3151 return (bool) $this->is_post_type_archive; 3152 3152 3153 $post_type_object = $this->get_queried_object();3153 $post_type_object = get_post_type_object( $this->get( 'post_type' ) ); 3154 3154 3155 3155 return in_array( $post_type_object->name, (array) $post_types ); -
trunk/src/wp-includes/template-loader.php
r22353 r25291 27 27 if ( is_404() && $template = get_404_template() ) : 28 28 elseif ( is_search() && $template = get_search_template() ) : 29 elseif ( is_post_type_archive() && $template = get_post_type_archive_template() ) : 29 30 elseif ( is_tax() && $template = get_taxonomy_template() ) : 30 31 elseif ( is_front_page() && $template = get_front_page_template() ) : -
trunk/src/wp-includes/template.php
r23665 r25291 71 71 72 72 return get_query_template( 'archive', $templates ); 73 } 74 75 /** 76 * Retrieve path of post type archive template in current or parent template. 77 * 78 * @since 3.7.0 79 * 80 * @return string 81 */ 82 function get_post_type_archive_template() { 83 $obj = get_post_type_object( get_query_var( 'post_type' ) ); 84 if ( ! $obj->has_archive ) 85 return ''; 86 87 return get_archive_template(); 73 88 } 74 89 -
trunk/tests/phpunit/tests/query/conditionals.php
r25287 r25291 649 649 $this->assertQueryTrue( 'is_404' ); 650 650 } 651 652 function test_post_type_archive_with_tax_query() { 653 delete_option( 'rewrite_rules' ); 654 655 $cpt_name = 'ptawtq'; 656 register_post_type( $cpt_name, array( 657 'taxonomies' => array( 'post_tag', 'category' ), 658 'rewrite' => true, 659 'has_archive' => true, 660 'public' => true 661 ) ); 662 663 $tag_id = $this->factory->tag->create( array( 'slug' => 'tag-slug' ) ); 664 $post_id = $this->factory->post->create( array( 'post_type' => $cpt_name ) ); 665 wp_set_object_terms( $post_id, $tag_id, 'post_tag' ); 666 667 $this->go_to( '/ptawtq/' ); 668 $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' ); 669 $this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) ); 670 671 add_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_tax_query' ) ); 672 673 $this->go_to( '/ptawtq/' ); 674 $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' ); 675 $this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) ); 676 677 remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_tax_query' ) ); 678 } 679 680 function pre_get_posts_with_tax_query( &$query ) { 681 $term = get_term_by( 'slug', 'tag-slug', 'post_tag' ); 682 $query->set( 'tax_query', array( 683 array( 'taxonomy' => 'post_tag', 'field' => 'term_id', 'terms' => $term->term_id ) 684 ) ); 685 } 651 686 }
Note: See TracChangeset
for help on using the changeset viewer.