Ticket #3373: get_page_uri.patch
| File get_page_uri.patch, 1.3 KB (added by , 19 years ago) |
|---|
-
wp-includes/post.php
1025 1025 return $result; 1026 1026 } 1027 1027 1028 function _get_page_uri_hierarchy($posts, $parent = 0, $parent_uri = '') { 1029 $result = array ( ); 1030 if ($posts) { foreach ($posts as $post) { 1031 if ($post->post_parent == $parent) { 1032 1033 $current_uri = urldecode($post->post_name); 1034 if($parent_uri != '') 1035 $current_uri = $parent_uri . '/'. $current_uri; 1036 $result[$post->ID] = $current_uri; 1037 $children = _get_page_uri_hierarchy($posts, $post->ID, $current_uri); 1038 $result += $children; //append $children to $result 1039 } 1040 } } 1041 return $result; 1042 } 1043 1028 1044 function get_page_uri($page_id) { 1029 $page = get_page($page_id); 1030 $uri = urldecode($page->post_name); 1045 global $uris, $wpdb; 1031 1046 1032 // A page cannot be it's own parent. 1033 if ( $page->post_parent == $page->ID ) 1034 return $uri; 1047 if(!is_array($uris)) 1048 $uris = _get_page_uri_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page' OR post_type='attachment'")); 1035 1049 1036 while ($page->post_parent != 0) { 1037 $page = get_page($page->post_parent); 1038 $uri = urldecode($page->post_name) . "/" . $uri; 1039 } 1040 1041 return $uri; 1050 return $uris[$page_id]; 1042 1051 } 1043 1052 1044 1053 function &get_pages($args = '') {