Changeset 3573 for trunk/wp-includes/template-functions-post.php
- Timestamp:
- 02/28/2006 03:57:08 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/template-functions-post.php
r3558 r3573 296 296 function &get_pages($args = '') { 297 297 global $wpdb; 298 299 298 parse_str($args, $r); 300 299 … … 305 304 if ( !isset($r['sort_order']) ) 306 305 $r['sort_order'] = 'ASC'; 306 if ( !isset($r['hierarchical']) ) 307 $r['hierarchical'] = 1; 307 308 308 309 $exclusions = ''; … … 328 329 update_page_cache($pages); 329 330 330 if ( $r['child_of'] )331 if ( $r['child_of'] || $r['hierarchical'] ) 331 332 $pages = & get_page_children($r['child_of'], $pages); 332 333 … … 334 335 } 335 336 337 function wp_dropdown_pages($args = '') { 338 parse_str($args, $r); 339 if ( !isset($r['depth']) ) 340 $r['depth'] = 0; 341 if ( !isset($r['child_of']) ) 342 $r['child_of'] = 0; 343 if ( !isset($r['echo']) ) 344 $r['echo'] = 1; 345 if ( !isset($r['selected']) ) 346 $r['selected'] = 0; 347 348 extract($r); 349 350 $pages = get_pages($args); 351 $output = ''; 352 353 if ( ! empty($pages) ) { 354 $output = "<select name='page_id'>\n"; 355 $output .= walk_page_tree($pages, $depth, '_page_dropdown_element', '', '', '', $selected); 356 $output .= "</select>\n"; 357 } 358 359 $output = apply_filters('wp_dropdown_pages', $output); 360 361 if ( $echo ) 362 echo $output; 363 364 return $output; 365 } 366 367 function _page_dropdown_element($output, $page, $depth, $selected) { 368 $pad = str_repeat(' ', $depth * 3); 369 370 $output .= "\t<option value=\"$page->ID\""; 371 if ( $page->ID == $selected ) 372 $output .= ' selected="selected"'; 373 $output .= '>'; 374 $title = wp_specialchars($page->post_title); 375 $output .= "$pad$title"; 376 $output .= "</option>\n"; 377 378 return $output; 379 } 336 380 337 381 function wp_list_pages($args = '') { … … 341 385 if ( !isset($r['show_date']) ) 342 386 $r['show_date'] = ''; 387 if ( !isset($r['date_format']) ) 388 $r['date_format'] = get_settings('date_format'); 343 389 if ( !isset($r['child_of']) ) 344 390 $r['child_of'] = 0; … … 351 397 352 398 // Query pages. 353 $pages = &get_pages($args);354 if ( $pages ) { 355 399 $pages = get_pages($args); 400 401 if ( !empty($pages) ) { 356 402 if ( $r['title_li'] ) 357 403 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>'; 358 404 359 // Now loop over all pages that were selected 360 $page_tree = Array(); 361 foreach ( $pages as $page ) { 362 // set the title for the current page 363 $page_tree[$page->ID]['title'] = $page->post_title; 364 $page_tree[$page->ID]['name'] = $page->post_name; 365 366 // set the selected date for the current page 367 // depending on the query arguments this is either 368 // the createtion date or the modification date 369 // as a unix timestamp. It will also always be in the 370 // ts field. 371 if ( !empty($r['show_date']) ) { 372 if ( 'modified' == $r['show_date'] ) 373 $page_tree[$page->ID]['ts'] = $page->post_modified; 374 else 375 $page_tree[$page->ID]['ts'] = $page->post_date; 376 } 377 378 // The tricky bit!! 379 // Using the parent ID of the current page as the 380 // array index we set the curent page as a child of that page. 381 // We can now start looping over the $page_tree array 382 // with any ID which will output the page links from that ID downwards. 383 if ( $page->post_parent != $page->ID) 384 $page_tree[$page->post_parent]['children'][] = $page->ID; 385 } 386 // Output of the pages starting with child_of as the root ID. 387 // child_of defaults to 0 if not supplied in the query. 388 $output .= _page_level_out($r['child_of'],$page_tree, $r, 0, false); 405 global $wp_query; 406 $current_page = $wp_query->get_queried_object_id(); 407 $output .= walk_page_tree($pages, $depth, '_page_list_element_start', '_page_list_element_end', '_page_list_level_start', '_page_list_level_end', $current_page, $r['show_date'], $r['date_format']); 408 389 409 if ( $r['title_li'] ) 390 410 $output .= '</ul></li>'; … … 399 419 } 400 420 401 402 function _page_level_out($parent, $page_tree, $args, $depth = 0, $echo = true) { 403 global $wp_query; 404 $queried_obj = $wp_query->get_queried_object(); 405 $output = ''; 406 421 function _page_list_level_start($output, $depth) { 422 $indent = str_repeat("\t", $depth); 423 $output .= "$indent<ul>\n"; 424 return $output; 425 } 426 427 function _page_list_level_end($output, $depth) { 428 $indent = str_repeat("\t", $depth); 429 $output .= "$indent</ul>\n"; 430 return $output; 431 } 432 433 function _page_list_element_start($output, $page, $depth, $current_page, $show_date, $date_format) { 407 434 if ( $depth ) 408 435 $indent = str_repeat("\t", $depth); 409 //$indent = join('', array_fill(0,$depth,"\t")); 410 411 if ( !is_array($page_tree[$parent]['children']) ) 412 return false; 413 414 foreach ( $page_tree[$parent]['children'] as $page_id ) { 415 $cur_page = $page_tree[$page_id]; 416 $title = $cur_page['title']; 417 418 $css_class = 'page_item'; 419 if ( $page_id == $queried_obj->ID ) 420 $css_class .= ' current_page_item'; 421 422 $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page_id) . '" title="' . wp_specialchars($title) . '">' . $title . '</a>'; 423 424 if ( isset($cur_page['ts']) ) { 425 $format = get_settings('date_format'); 426 if ( isset($args['date_format']) ) 427 $format = $args['date_format']; 428 $output .= " " . mysql2date($format, $cur_page['ts']); 429 } 430 431 if ( isset($cur_page['children']) && is_array($cur_page['children']) ) { 432 $new_depth = $depth + 1; 433 434 if ( !$args['depth'] || $depth < ($args['depth']-1) ) { 435 $output .= "$indent<ul>\n"; 436 $output .= _page_level_out($page_id, $page_tree, $args, $new_depth, false); 437 $output .= "$indent</ul>\n"; 438 } 439 } 440 $output .= "$indent</li>\n"; 441 } 442 if ( $echo ) 443 echo $output; 444 else 445 return $output; 436 437 $css_class = 'page_item'; 438 if ( $page->ID == $current_page ) 439 $css_class .= ' current_page_item'; 440 441 $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . wp_specialchars($page->post_title) . '">' . $page->post_title . '</a>'; 442 443 if ( !empty($show_date) ) { 444 if ( 'modified' == $show_date ) 445 $time = $page->post_modified; 446 else 447 $time = $page->post_date; 448 449 $output .= " " . mysql2date($date_format, $time); 450 } 451 452 return $output; 453 } 454 455 function _page_list_element_end($output, $page, $depth) { 456 $output .= "</li>\n"; 457 458 return $output; 446 459 } 447 460
Note: See TracChangeset
for help on using the changeset viewer.