Changeset 34109 for trunk/src/wp-includes/post-template.php
- Timestamp:
- 09/14/2015 02:58:40 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post-template.php
r34108 r34109 1322 1322 } 1323 1323 1324 /**1325 * Create HTML list of pages.1326 *1327 * @since 2.1.01328 * @uses Walker1329 */1330 class Walker_Page extends Walker {1331 /**1332 * @see Walker::$tree_type1333 * @since 2.1.01334 * @var string1335 */1336 public $tree_type = 'page';1337 1338 /**1339 * @see Walker::$db_fields1340 * @since 2.1.01341 * @todo Decouple this.1342 * @var array1343 */1344 public $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');1345 1346 /**1347 * @see Walker::start_lvl()1348 * @since 2.1.01349 *1350 * @param string $output Passed by reference. Used to append additional content.1351 * @param int $depth Depth of page. Used for padding.1352 * @param array $args1353 */1354 public function start_lvl( &$output, $depth = 0, $args = array() ) {1355 $indent = str_repeat("\t", $depth);1356 $output .= "\n$indent<ul class='children'>\n";1357 }1358 1359 /**1360 * @see Walker::end_lvl()1361 * @since 2.1.01362 *1363 * @param string $output Passed by reference. Used to append additional content.1364 * @param int $depth Depth of page. Used for padding.1365 * @param array $args1366 */1367 public function end_lvl( &$output, $depth = 0, $args = array() ) {1368 $indent = str_repeat("\t", $depth);1369 $output .= "$indent</ul>\n";1370 }1371 1372 /**1373 * @see Walker::start_el()1374 * @since 2.1.01375 *1376 * @param string $output Passed by reference. Used to append additional content.1377 * @param object $page Page data object.1378 * @param int $depth Depth of page. Used for padding.1379 * @param int $current_page Page ID.1380 * @param array $args1381 */1382 public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {1383 if ( $depth ) {1384 $indent = str_repeat( "\t", $depth );1385 } else {1386 $indent = '';1387 }1388 1389 $css_class = array( 'page_item', 'page-item-' . $page->ID );1390 1391 if ( isset( $args['pages_with_children'][ $page->ID ] ) ) {1392 $css_class[] = 'page_item_has_children';1393 }1394 1395 if ( ! empty( $current_page ) ) {1396 $_current_page = get_post( $current_page );1397 if ( $_current_page && in_array( $page->ID, $_current_page->ancestors ) ) {1398 $css_class[] = 'current_page_ancestor';1399 }1400 if ( $page->ID == $current_page ) {1401 $css_class[] = 'current_page_item';1402 } elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {1403 $css_class[] = 'current_page_parent';1404 }1405 } elseif ( $page->ID == get_option('page_for_posts') ) {1406 $css_class[] = 'current_page_parent';1407 }1408 1409 /**1410 * Filter the list of CSS classes to include with each page item in the list.1411 *1412 * @since 2.8.01413 *1414 * @see wp_list_pages()1415 *1416 * @param array $css_class An array of CSS classes to be applied1417 * to each list item.1418 * @param WP_Post $page Page data object.1419 * @param int $depth Depth of page, used for padding.1420 * @param array $args An array of arguments.1421 * @param int $current_page ID of the current page.1422 */1423 $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );1424 1425 if ( '' === $page->post_title ) {1426 /* translators: %d: ID of a post */1427 $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID );1428 }1429 1430 $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];1431 $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after'];1432 1433 /** This filter is documented in wp-includes/post-template.php */1434 $output .= $indent . sprintf(1435 '<li class="%s"><a href="%s">%s%s%s</a>',1436 $css_classes,1437 get_permalink( $page->ID ),1438 $args['link_before'],1439 apply_filters( 'the_title', $page->post_title, $page->ID ),1440 $args['link_after']1441 );1442 1443 if ( ! empty( $args['show_date'] ) ) {1444 if ( 'modified' == $args['show_date'] ) {1445 $time = $page->post_modified;1446 } else {1447 $time = $page->post_date;1448 }1449 1450 $date_format = empty( $args['date_format'] ) ? '' : $args['date_format'];1451 $output .= " " . mysql2date( $date_format, $time );1452 }1453 }1454 1455 /**1456 * @see Walker::end_el()1457 * @since 2.1.01458 *1459 * @param string $output Passed by reference. Used to append additional content.1460 * @param object $page Page data object. Not used.1461 * @param int $depth Depth of page. Not Used.1462 * @param array $args1463 */1464 public function end_el( &$output, $page, $depth = 0, $args = array() ) {1465 $output .= "</li>\n";1466 }1467 1468 }1469 1470 /**1471 * Create HTML dropdown list of pages.1472 *1473 * @since 2.1.01474 * @uses Walker1475 */1476 class Walker_PageDropdown extends Walker {1477 /**1478 * @see Walker::$tree_type1479 * @since 2.1.01480 * @var string1481 */1482 public $tree_type = 'page';1483 1484 /**1485 * @see Walker::$db_fields1486 * @since 2.1.01487 * @todo Decouple this1488 * @var array1489 */1490 public $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');1491 1492 /**1493 * @see Walker::start_el()1494 * @since 2.1.01495 *1496 * @param string $output Passed by reference. Used to append additional content.1497 * @param object $page Page data object.1498 * @param int $depth Depth of page in reference to parent pages. Used for padding.1499 * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option1500 * element. Uses 'value_field' argument to fill "value" attribute. See {@see wp_dropdown_pages()}.1501 * @param int $id1502 */1503 public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) {1504 $pad = str_repeat(' ', $depth * 3);1505 1506 if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) {1507 $args['value_field'] = 'ID';1508 }1509 1510 $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $page->{$args['value_field']} ) . "\"";1511 if ( $page->ID == $args['selected'] )1512 $output .= ' selected="selected"';1513 $output .= '>';1514 1515 $title = $page->post_title;1516 if ( '' === $title ) {1517 /* translators: %d: ID of a post */1518 $title = sprintf( __( '#%d (no title)' ), $page->ID );1519 }1520 1521 /**1522 * Filter the page title when creating an HTML drop-down list of pages.1523 *1524 * @since 3.1.01525 *1526 * @param string $title Page title.1527 * @param object $page Page data object.1528 */1529 $title = apply_filters( 'list_pages', $title, $page );1530 $output .= $pad . esc_html( $title );1531 $output .= "</option>\n";1532 }1533 }1534 1535 1324 // 1536 1325 // Attachments
Note: See TracChangeset
for help on using the changeset viewer.