Changeset 38951 for trunk/src/wp-includes/post-template.php
- Timestamp:
- 10/26/2016 08:06:43 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post-template.php
r38798 r38951 595 595 $classes[] = 'error404'; 596 596 597 if ( is_sing le() ) {597 if ( is_singular() ) { 598 598 $post_id = $wp_query->get_queried_object_id(); 599 599 $post = $wp_query->get_queried_object(); 600 601 $classes[] = 'single'; 602 if ( isset( $post->post_type ) ) { 603 $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id); 604 $classes[] = 'postid-' . $post_id; 605 606 // Post Format 607 if ( post_type_supports( $post->post_type, 'post-formats' ) ) { 608 $post_format = get_post_format( $post->ID ); 609 610 if ( $post_format && !is_wp_error($post_format) ) 611 $classes[] = 'single-format-' . sanitize_html_class( $post_format ); 612 else 613 $classes[] = 'single-format-standard'; 600 $post_type = $post->post_type; 601 602 if ( is_page_template() ) { 603 $classes[] = "{$post_type}-template"; 604 605 $template_slug = get_page_template_slug( $post_id ); 606 $template_parts = explode( '/', $template_slug ); 607 608 foreach ( $template_parts as $part ) { 609 $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) ); 610 } 611 $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace( '.', '-', $template_slug ) ); 612 } else { 613 $classes[] = "{$post_type}-template-default"; 614 } 615 616 if ( is_single() ) { 617 $classes[] = 'single'; 618 if ( isset( $post->post_type ) ) { 619 $classes[] = 'single-' . sanitize_html_class( $post->post_type, $post_id ); 620 $classes[] = 'postid-' . $post_id; 621 622 // Post Format 623 if ( post_type_supports( $post->post_type, 'post-formats' ) ) { 624 $post_format = get_post_format( $post->ID ); 625 626 if ( $post_format && !is_wp_error($post_format) ) 627 $classes[] = 'single-format-' . sanitize_html_class( $post_format ); 628 else 629 $classes[] = 'single-format-standard'; 630 } 614 631 } 615 632 } … … 620 637 $classes[] = 'attachmentid-' . $post_id; 621 638 $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type ); 639 } elseif ( is_page() ) { 640 $classes[] = 'page'; 641 642 $page_id = $wp_query->get_queried_object_id(); 643 644 $post = get_post($page_id); 645 646 $classes[] = 'page-id-' . $page_id; 647 648 if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) { 649 $classes[] = 'page-parent'; 650 } 651 652 if ( $post->post_parent ) { 653 $classes[] = 'page-child'; 654 $classes[] = 'parent-pageid-' . $post->post_parent; 655 } 622 656 } 623 657 } elseif ( is_archive() ) { … … 671 705 $classes[] = 'term-' . $term->term_id; 672 706 } 673 }674 } elseif ( is_page() ) {675 $classes[] = 'page';676 677 $page_id = $wp_query->get_queried_object_id();678 679 $post = get_post($page_id);680 681 $classes[] = 'page-id-' . $page_id;682 683 if ( get_pages( array( 'parent' => $page_id, 'number' => 1 ) ) ) {684 $classes[] = 'page-parent';685 }686 687 if ( $post->post_parent ) {688 $classes[] = 'page-child';689 $classes[] = 'parent-pageid-' . $post->post_parent;690 }691 if ( is_page_template() ) {692 $classes[] = 'page-template';693 694 $template_slug = get_page_template_slug( $page_id );695 $template_parts = explode( '/', $template_slug );696 697 foreach ( $template_parts as $part ) {698 $classes[] = 'page-template-' . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) );699 }700 $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', $template_slug ) );701 } else {702 $classes[] = 'page-template-default';703 707 } 704 708 } … … 1622 1626 * @since 2.5.0 1623 1627 * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates. 1628 * @since 4.7.0 Now works with any post type, not just pages. 1624 1629 * 1625 1630 * @param string|array $template The specific template name or array of templates to match. … … 1627 1632 */ 1628 1633 function is_page_template( $template = '' ) { 1629 if ( ! is_page() )1630 return false;1631 1632 1634 $page_template = get_page_template_slug( get_queried_object_id() ); 1633 1635 … … 1650 1652 1651 1653 /** 1652 * Get the specific template name for a page.1654 * Get the specific template name for a given post. 1653 1655 * 1654 1656 * @since 3.4.0 1655 * 1656 * @param int $post_id Optional. The page ID to check. Defaults to the current post, when used in the loop. 1657 * @since 4.7.0 Now works with any post type, not just pages. 1658 * 1659 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. 1657 1660 * @return string|false Page template filename. Returns an empty string when the default page template 1658 * is in use. Returns false if the post is not a page. 1659 */ 1660 function get_page_template_slug( $post_id = null ) { 1661 $post = get_post( $post_id ); 1662 if ( ! $post || 'page' != $post->post_type ) 1661 * is in use. Returns false if the post does not exist. 1662 */ 1663 function get_page_template_slug( $post = null ) { 1664 $post = get_post( $post ); 1665 1666 if ( ! $post ) { 1663 1667 return false; 1668 } 1669 1664 1670 $template = get_post_meta( $post->ID, '_wp_page_template', true ); 1665 if ( ! $template || 'default' == $template ) 1671 1672 if ( ! $template || 'default' == $template ) { 1666 1673 return ''; 1674 } 1675 1667 1676 return $template; 1668 1677 }
Note: See TracChangeset
for help on using the changeset viewer.