Changeset 3851 for trunk/wp-includes/post-template.php
- Timestamp:
- 06/07/2006 11:17:59 PM (19 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post-template.php
r3845 r3851 1 1 <?php 2 2 3 function get_the_password_form() { 4 $output = '<form action="' . get_settings('siteurl') . '/wp-pass.php" method="post"> 5 <p>' . __("This post is password protected. To view it please enter your password below:") . '</p> 6 <p><label>' . __("Password:") . ' <input name="post_password" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . __("Submit") . '" /></p> 7 </form> 8 '; 9 return $output; 10 } 11 3 // 4 // "The Loop" post functions 5 // 12 6 13 7 function the_ID() { … … 16 10 } 17 11 12 18 13 function get_the_ID() { 19 14 global $id; 20 15 return $id; 21 16 } 17 22 18 23 19 function the_title($before = '', $after = '', $echo = true) { … … 43 39 } 44 40 41 function the_guid( $id = 0 ) { 42 echo get_the_guid($id); 43 } 45 44 46 45 function get_the_guid( $id = 0 ) { … … 49 48 return apply_filters('get_the_guid', $post->guid); 50 49 } 51 52 53 function the_guid( $id = 0 ) {54 echo get_the_guid($id);55 }56 57 50 58 51 function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') { … … 191 184 192 185 193 /* 194 Post-meta: Custom per-post fields. 195 */ 196 197 198 function get_post_custom( $post_id = 0 ) { 199 global $id, $post_meta_cache, $wpdb; 200 201 if ( ! $post_id ) 202 $post_id = $id; 203 204 if ( isset($post_meta_cache[$post_id]) ) 205 return $post_meta_cache[$post_id]; 206 207 if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = '$post_id' ORDER BY post_id, meta_key", ARRAY_A) ) { 208 // Change from flat structure to hierarchical: 209 $post_meta_cache = array(); 210 foreach ( $meta_list as $metarow ) { 211 $mpid = $metarow['post_id']; 212 $mkey = $metarow['meta_key']; 213 $mval = $metarow['meta_value']; 214 215 // Force subkeys to be array type: 216 if ( !isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]) ) 217 $post_meta_cache[$mpid] = array(); 218 219 if ( !isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]) ) 220 $post_meta_cache[$mpid]["$mkey"] = array(); 221 222 // Add a value to the current pid/key: 223 $post_meta_cache[$mpid][$mkey][] = $mval; 224 } 225 return $post_meta_cache[$mpid]; 226 } 227 } 228 229 230 function get_post_custom_keys() { 231 $custom = get_post_custom(); 232 233 if ( ! is_array($custom) ) 234 return; 235 236 if ( $keys = array_keys($custom) ) 237 return $keys; 238 } 239 240 241 function get_post_custom_values( $key = '' ) { 242 $custom = get_post_custom(); 243 244 return $custom[$key]; 245 } 186 // 187 // Post-meta: Custom per-post fields. 188 // 246 189 247 190 … … 275 218 276 219 277 /* 278 Pages 279 */ 220 // 221 // Pages 222 // 223 224 function wp_dropdown_pages($args = '') { 225 if ( is_array($args) ) 226 $r = &$args; 227 else 228 parse_str($args, $r); 229 230 $defaults = array('depth' => 0, 'child_of' => 0, 'selected' => 0, 'echo' => 1, 231 'name' => 'page_id'); 232 $r = array_merge($defaults, $r); 233 extract($r); 234 235 $pages = get_pages($r); 236 $output = ''; 237 238 if ( ! empty($pages) ) { 239 $output = "<select name='$name'>\n"; 240 $output .= walk_page_dropdown_tree($pages, $depth, $r); 241 $output .= "</select>\n"; 242 } 243 244 $output = apply_filters('wp_dropdown_pages', $output); 245 246 if ( $echo ) 247 echo $output; 248 249 return $output; 250 } 251 252 function wp_list_pages($args = '') { 253 if ( is_array($args) ) 254 $r = &$args; 255 else 256 parse_str($args, $r); 257 258 $defaults = array('depth' => 0, 'show_date' => '', 'date_format' => get_settings('date_format'), 259 'child_of' => 0, 'title_li' => __('Pages'), 'echo' => 1); 260 $r = array_merge($defaults, $r); 261 262 $output = ''; 263 264 // Query pages. 265 $pages = get_pages($r); 266 267 if ( !empty($pages) ) { 268 if ( $r['title_li'] ) 269 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>'; 270 271 global $wp_query; 272 $current_page = $wp_query->get_queried_object_id(); 273 $output .= walk_page_tree($pages, $r['depth'], $current_page, $r['show_date'], $r['date_format']); 274 275 if ( $r['title_li'] ) 276 $output .= '</ul></li>'; 277 } 278 279 $output = apply_filters('wp_list_pages', $output); 280 281 if ( $r['echo'] ) 282 echo $output; 283 else 284 return $output; 285 } 286 287 // 288 // Page helpers 289 // 280 290 281 291 function walk_page_tree() { … … 291 301 } 292 302 293 function &get_page_children($page_id, $pages) { 294 global $page_cache; 295 296 if ( empty($pages) ) 297 $pages = &$page_cache; 298 299 $page_list = array(); 300 foreach ( $pages as $page ) { 301 if ( $page->post_parent == $page_id ) { 302 $page_list[] = $page; 303 if ( $children = get_page_children($page->ID, $pages) ) 304 $page_list = array_merge($page_list, $children); 305 } 306 } 307 return $page_list; 308 } 309 310 311 function &get_pages($args = '') { 312 global $wpdb; 313 314 if ( is_array($args) ) 315 $r = &$args; 316 else 317 parse_str($args, $r); 318 319 $defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 320 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => ''); 321 $r = array_merge($defaults, $r); 322 extract($r); 323 324 $inclusions = ''; 325 if ( !empty($include) ) { 326 $child_of = 0; //ignore child_of, exclude, meta_key, and meta_value params if using include 327 $exclude = ''; 328 $meta_key = ''; 329 $meta_value = ''; 330 $incpages = preg_split('/[\s,]+/',$include); 331 if ( count($incpages) ) { 332 foreach ( $incpages as $incpage ) { 333 if (empty($inclusions)) 334 $inclusions = ' AND ( ID = ' . intval($incpage) . ' '; 335 else 336 $inclusions .= ' OR ID = ' . intval($incpage) . ' '; 337 } 338 } 339 } 340 if (!empty($inclusions)) 341 $inclusions .= ')'; 342 343 $exclusions = ''; 344 if ( !empty($exclude) ) { 345 $expages = preg_split('/[\s,]+/',$exclude); 346 if ( count($expages) ) { 347 foreach ( $expages as $expage ) { 348 if (empty($exclusions)) 349 $exclusions = ' AND ( ID <> ' . intval($expage) . ' '; 350 else 351 $exclusions .= ' AND ID <> ' . intval($expage) . ' '; 352 } 353 } 354 } 355 if (!empty($exclusions)) 356 $exclusions .= ')'; 357 358 $query = "SELECT * FROM $wpdb->posts " ; 359 $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ; 360 $query .= " WHERE (post_type = 'page' AND post_status = 'publish') $exclusions $inclusions " ; 361 $query .= ( empty( $meta_key ) | empty($meta_value) ? "" : " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' )" ) ; 362 $query .= " ORDER BY " . $sort_column . " " . $sort_order ; 363 364 $pages = $wpdb->get_results($query); 365 $pages = apply_filters('get_pages', $pages, $r); 366 367 if ( empty($pages) ) 368 return array(); 369 370 // Update cache. 371 update_page_cache($pages); 372 373 if ( $child_of || $hierarchical ) 374 $pages = & get_page_children($child_of, $pages); 375 376 return $pages; 377 } 378 379 function wp_dropdown_pages($args = '') { 380 if ( is_array($args) ) 381 $r = &$args; 382 else 383 parse_str($args, $r); 384 385 $defaults = array('depth' => 0, 'child_of' => 0, 'selected' => 0, 'echo' => 1, 386 'name' => 'page_id'); 387 $r = array_merge($defaults, $r); 388 extract($r); 389 390 $pages = get_pages($r); 391 $output = ''; 392 393 if ( ! empty($pages) ) { 394 $output = "<select name='$name'>\n"; 395 $output .= walk_page_dropdown_tree($pages, $depth, $r); 396 $output .= "</select>\n"; 397 } 398 399 $output = apply_filters('wp_dropdown_pages', $output); 400 401 if ( $echo ) 402 echo $output; 403 404 return $output; 405 } 406 407 function wp_list_pages($args = '') { 408 if ( is_array($args) ) 409 $r = &$args; 410 else 411 parse_str($args, $r); 412 413 $defaults = array('depth' => 0, 'show_date' => '', 'date_format' => get_settings('date_format'), 414 'child_of' => 0, 'title_li' => __('Pages'), 'echo' => 1); 415 $r = array_merge($defaults, $r); 416 417 $output = ''; 418 419 // Query pages. 420 $pages = get_pages($r); 421 422 if ( !empty($pages) ) { 423 if ( $r['title_li'] ) 424 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>'; 425 426 global $wp_query; 427 $current_page = $wp_query->get_queried_object_id(); 428 $output .= walk_page_tree($pages, $r['depth'], $current_page, $r['show_date'], $r['date_format']); 429 430 if ( $r['title_li'] ) 431 $output .= '</ul></li>'; 432 } 433 434 $output = apply_filters('wp_list_pages', $output); 435 436 if ( $r['echo'] ) 437 echo $output; 438 else 439 return $output; 440 } 303 // 304 // Attachments 305 // 441 306 442 307 function the_attachment_link($id = 0, $fullsize = false, $max_dims = false) { … … 562 427 } 563 428 429 // 430 // Misc 431 // 432 433 function get_the_password_form() { 434 $output = '<form action="' . get_settings('siteurl') . '/wp-pass.php" method="post"> 435 <p>' . __("This post is password protected. To view it please enter your password below:") . '</p> 436 <p><label>' . __("Password:") . ' <input name="post_password" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . __("Submit") . '" /></p> 437 </form> 438 '; 439 return $output; 440 } 441 564 442 ?>
Note: See TracChangeset
for help on using the changeset viewer.