Changeset 13774
- Timestamp:
- 03/20/2010 02:23:52 AM (15 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/link-template.php
r13733 r13774 188 188 $draft_or_pending = 'draft' == $post->post_status || 'pending' == $post->post_status; 189 189 190 $post_type = get_post_type_object($post->post_type); 191 190 192 if ( !empty($post_link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) { 191 $post_link = ( $leavename ) ? $post_link : str_replace("%$post->post_type%", $slug, $post_link); 193 if ( ! $leavename ) { 194 if ( $post_type->hierarchical ) 195 $slug = get_page_uri($id); 196 $post_link = str_replace("%$post->post_type%", $slug, $post_link); 197 } 192 198 $post_link = home_url( user_trailingslashit($post_link) ); 193 199 } else { 194 $post_type = get_post_type_object($post->post_type);195 200 if ( $post_type->query_var && ( isset($post->post_status) && !$draft_or_pending ) ) 196 201 $post_link = add_query_arg($post_type->query_var, $slug, ''); … … 296 301 $link = false; 297 302 298 if ( ! $id) {303 if ( ! $id) 299 304 $id = (int) $post->ID; 300 }301 305 302 306 $object = get_post($id); … … 307 311 else 308 312 $parentlink = get_permalink( $object->post_parent ); 313 309 314 if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') ) 310 315 $name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker 311 316 else 312 317 $name = $object->post_name; 313 if (strpos($parentlink, '?') === false) 318 319 if ( strpos($parentlink, '?') === false ) 314 320 $link = user_trailingslashit( trailingslashit($parentlink) . $name ); 315 321 } 316 322 317 if ( ! $link ) {323 if ( ! $link ) 318 324 $link = trailingslashit(get_bloginfo('url')) . "?attachment_id=$id"; 319 }320 325 321 326 return apply_filters('attachment_link', $link, $id); -
trunk/wp-includes/post.php
r13773 r13774 855 855 if ( !isset($args->rewrite['with_front']) ) 856 856 $args->rewrite['with_front'] = true; 857 $wp_rewrite->add_rewrite_tag("%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name="); 857 if ( $args->hierarchical ) 858 $wp_rewrite->add_rewrite_tag("%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name="); 859 else 860 $wp_rewrite->add_rewrite_tag("%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name="); 858 861 $wp_rewrite->add_permastruct($post_type, "{$args->rewrite['slug']}/%$post_type%", $args->rewrite['with_front'], $args->permalink_epmask); 859 862 } … … 2750 2753 * @return mixed Null when complete. 2751 2754 */ 2752 function get_page_by_path($page_path, $output = OBJECT ) {2755 function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') { 2753 2756 global $wpdb; 2754 2757 $page_path = rawurlencode(urldecode($page_path)); … … 2762 2765 $full_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir); 2763 2766 2764 $pages = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = %s AND (post_type = 'page' OR post_type = 'attachment')", $leaf_path));2767 $pages = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = %s AND (post_type = %s OR post_type = 'attachment')", $leaf_path, $post_type )); 2765 2768 2766 2769 if ( empty($pages) ) 2767 2770 return null; 2768 2771 2769 foreach ( $pages as $page) {2772 foreach ( $pages as $page ) { 2770 2773 $path = '/' . $leaf_path; 2771 2774 $curpage = $page; 2772 while ( $curpage->post_parent != 0) {2773 $curpage = $wpdb->get_row( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE ID = %d and post_type ='page'", $curpage->post_parent));2775 while ( $curpage->post_parent != 0 ) { 2776 $curpage = $wpdb->get_row( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE ID = %d and post_type = %s", $curpage->post_parent, $post_type )); 2774 2777 $path = '/' . $curpage->post_name . $path; 2775 2778 } 2776 2779 2777 2780 if ( $path == $full_path ) 2778 return get_page($page->ID, $output );2781 return get_page($page->ID, $output, $post_type); 2779 2782 } 2780 2783 -
trunk/wp-includes/query.php
r13770 r13774 1713 1713 $where .= " AND DAYOFMONTH($wpdb->posts.post_date)='" . $q['day'] . "'"; 1714 1714 1715 if ('' != $q['name']) { 1715 if ( !empty($q['post_type']) && !empty($q[ $q['post_type'] ]) ) { 1716 $q[ $q['post_type'] ] = str_replace('%2F', '/', urlencode(urldecode($q[ $q['post_type'] ]))); 1717 $post_type_object = get_post_type_object($q['post_type']); 1718 if ( ! $post_type_object->hierarchical || strpos($q[ $q['post_type'] ], '/') === false) { 1719 $q['name'] = $q[ $q['post_type'] ] = sanitize_title($q[ $q['post_type'] ]); 1720 $where .= " AND $wpdb->posts.post_name = '" . $q[ $q['post_type'] ] . "'"; 1721 } else { 1722 // Hierarchical post type, need to look deeper to see if its an attachment or this post_type 1723 if ( isset($this->queried_object_id) ) { 1724 $reqpage = $this->queried_object_id; 1725 } else { 1726 $reqpage = get_page_by_path($q[ $q['post_type'] ], OBJECT, $q['post_type']); 1727 if ( !empty($reqpage) ) 1728 $reqpage = $reqpage->ID; 1729 else 1730 $reqpage = 0; 1731 } 1732 $where .= " AND ($wpdb->posts.ID = '$reqpage')"; 1733 $reqpage_obj = get_page($reqpage); 1734 if ( is_object($reqpage_obj) && 'attachment' == $reqpage_obj->post_type ) { 1735 $this->is_attachment = true; 1736 $q['attachment_id'] = $reqpage; 1737 $post_type = $q['post_type'] = 'attachment'; 1738 } 1739 } 1740 } elseif ( '' != $q['name'] ) { 1716 1741 $q['name'] = sanitize_title($q['name']); 1717 1742 $where .= " AND $wpdb->posts.post_name = '" . $q['name'] . "'"; 1718 } else if ('' != $q['pagename']) {1743 } elseif ( '' != $q['pagename'] ) { 1719 1744 if ( isset($this->queried_object_id) ) 1720 1745 $reqpage = $this->queried_object_id; … … 1728 1753 1729 1754 $page_for_posts = get_option('page_for_posts'); 1730 if ( ('page' != get_option('show_on_front') ) || 1755 if ( ('page' != get_option('show_on_front') ) || empty($page_for_posts) || ( $reqpage != $page_for_posts ) ) { 1731 1756 $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename']))); 1732 1757 $page_paths = '/' . trim($q['pagename'], '/'); -
trunk/wp-includes/rewrite.php
r13773 r13774 1437 1437 foreach ( get_post_types( array('_builtin' => false ) ) as $ptype ) { 1438 1438 if ( strpos($struct, "%$ptype%") !== false ) { 1439 $ptype = get_post_type_object($ptype); 1439 1440 $post = true; 1440 $page = false;1441 $page = $ptype->hierarchical; // This is for page style attachment url's 1441 1442 break; 1442 1443 }
Note: See TracChangeset
for help on using the changeset viewer.