Changeset 2022 for trunk/wp-includes/template-functions-post.php
- Timestamp:
- 12/30/2004 07:41:14 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/template-functions-post.php
r1976 r2022 322 322 // 323 323 324 function wp_list_pages($args = '') {324 function get_pages($args = '') { 325 325 global $wpdb; 326 326 327 327 parse_str($args, $r); 328 328 329 if (!isset($r['child_of'])) $r['child_of'] = 0; 329 if (!isset($r['depth'])) $r['depth'] = 0;330 if (!isset($r['show_date'])) $r['show_date'] = '';331 330 if (!isset($r['sort_column'])) $r['sort_column'] = 'post_title'; 332 331 if (!isset($r['sort_order'])) $r['sort_order'] = 'ASC'; 333 334 332 335 333 $exclusions = ''; … … 343 341 } 344 342 345 $option_dates = ''; 346 if (! empty($r['show_date'])) { 347 if ('modified' == $r['show_date']) 348 $option_dates = ",UNIX_TIMESTAMP(post_modified) AS ts"; 349 else 350 $option_dates = ",UNIX_TIMESTAMP(post_date) AS ts"; 351 } 343 $dates = ",UNIX_TIMESTAMP(post_modified) AS time_modified"; 344 $dates .= ",UNIX_TIMESTAMP(post_date) AS time_created"; 352 345 353 346 $post_parent = ''; … … 355 348 $post_parent = ' AND post_parent=' . $r['child_of'] . ' '; 356 349 } 350 357 351 $pages = $wpdb->get_results("SELECT " . 358 352 "ID, post_title,post_parent " . 359 "$ option_dates " .353 "$dates " . 360 354 "FROM $wpdb->posts " . 361 355 "WHERE post_status = 'static' " . … … 363 357 "$exclusions " . 364 358 "ORDER BY " . $r['sort_column'] . " " . $r['sort_order']); 359 360 return $pages; 361 } 362 363 function wp_list_pages($args = '') { 364 parse_str($args, $r); 365 if (!isset($r['depth'])) $r['depth'] = 0; 366 if (!isset($r['show_date'])) $r['show_date'] = ''; 367 if (!isset($r['child_of'])) $r['child_of'] = 0; 368 369 // Query pages. 370 $pages = get_pages($args); 371 372 // Now loop over all pages that were selected 365 373 $page_tree = Array(); 366 374 foreach($pages as $page) { 375 // set the title for the current page 367 376 $page_tree[$page->ID]['title'] = $page->post_title; 368 377 369 if(!empty($r['show_date'])) { 370 $page_tree[$page->ID]['ts'] = $page->ts; 371 } 372 $page_tree[$page->post_parent]['children'][] = $page->ID; 373 } 374 page_level_out($r['child_of'],$page_tree, $r); 375 } 376 377 function page_level_out($parent, $page_tree, $args, $depth = 0) { 378 // set the selected date for the current page 379 // depending on the query arguments this is either 380 // the createtion date or the modification date 381 // as a unix timestamp. It will also always be in the 382 // ts field. 383 if (! empty($r['show_date'])) { 384 if ('modified' == $r['show_date']) 385 $page_tree[$page->ID]['ts'] = $page->date_modified; 386 else 387 $page_tree[$page->ID]['ts'] = $page->date_created; 388 } 389 390 // The tricky bit!! 391 // Using the parent ID of the current page as the 392 // array index we set the curent page as a child of that page. 393 // We can now start looping over the $page_tree array 394 // with any ID which will output the page links from that ID downwards. 395 $page_tree[$page->post_parent]['children'][] = $page->ID; 396 } 397 // Output of the pages starting with child_of as the root ID. 398 // child_of defaults to 0 if not supplied in the query. 399 _page_level_out($r['child_of'],$page_tree, $r); 400 } 401 402 function _page_level_out($parent, $page_tree, $args, $depth = 0) { 403 global $wp_query; 404 405 $queried_obj = $wp_query->get_queried_object(); 406 378 407 if($depth) 379 408 $indent = join(array_fill(0,$depth,"\t")); … … 382 411 $cur_page = $page_tree[$page_id]; 383 412 $title = $cur_page['title']; 384 echo $indent . '<li><a href="' . get_page_link($page_id) . '" title="' . wp_specialchars($title) . '">' . $title . '</a>'; 413 414 $css_class = 'page_item'; 415 if( $page_id == $queried_obj->ID) { 416 $css_class .= ' current_page_item'; 417 } 418 419 echo $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page_id) . '" title="' . wp_specialchars($title) . '">' . $title . '</a>'; 420 385 421 if(isset($cur_page['ts'])) { 386 422 $format = get_settings('date_format'); … … 396 432 397 433 if(!$args['depth'] || $depth < ($args['depth']-1)) { 398 page_level_out($page_id,$page_tree, $args, $new_depth);434 _page_level_out($page_id,$page_tree, $args, $new_depth); 399 435 } 400 436 echo "$indent</ul>\n"; 401 437 } 402 438 echo "$indent</li>\n"; 403 404 439 } 405 440 }
Note: See TracChangeset
for help on using the changeset viewer.