Ticket #14161: 14161.2.patch
File 14161.2.patch, 6.6 KB (added by , 14 years ago) |
---|
-
wp-includes/general-template.php
516 516 function wp_title($sep = '»', $display = true, $seplocation = '') { 517 517 global $wpdb, $wp_locale, $wp_query; 518 518 519 $cat = get_query_var('cat');520 $tag = get_query_var('tag_id');521 $category_name = get_query_var('category_name');522 $author = get_query_var('author');523 $author_name = get_query_var('author_name');524 519 $m = get_query_var('m'); 525 520 $year = get_query_var('year'); 526 521 $monthnum = get_query_var('monthnum'); … … 530 525 531 526 $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary 532 527 533 // If there's a category 534 if ( !empty($cat) ) { 535 // category exclusion 536 if ( !stristr($cat,'-') ) 537 $title = apply_filters('single_cat_title', get_the_category_by_ID($cat)); 538 } elseif ( !empty($category_name) ) { 539 if ( stristr($category_name,'/') ) { 540 $category_name = explode('/',$category_name); 541 if ( $category_name[count($category_name)-1] ) 542 $category_name = $category_name[count($category_name)-1]; // no trailing slash 543 else 544 $category_name = $category_name[count($category_name)-2]; // there was a trailling slash 545 } 546 $cat = get_term_by('slug', $category_name, 'category', OBJECT, 'display'); 547 if ( $cat ) 548 $title = apply_filters('single_cat_title', $cat->name); 528 // If there is a post 529 if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) { 530 $title = single_post_title( '', false ); 549 531 } 550 532 551 if ( !empty($tag) ) { 552 $tag = get_term($tag, 'post_tag', OBJECT, 'display'); 553 if ( is_wp_error( $tag ) ) 554 return $tag; 555 if ( ! empty($tag->name) ) 556 $title = apply_filters('single_tag_title', $tag->name); 533 // If there's a category or tag 534 if ( is_category() || is_tag() ) { 535 $title = single_term_title( '', false ); 557 536 } 558 537 538 // If there's a taxonomy 539 if ( is_tax() ) { 540 $tax = get_taxonomy( get_query_var('taxonomy') ); 541 $title = single_term_title( $tax->labels->name . $t_sep, false ); 542 } 543 559 544 // If there's an author 560 if ( !empty($author) ) {561 $ title = get_userdata($author);562 $title = $ title->display_name;545 if ( is_author() ) { 546 $author = $wp_query->get_queried_object(); 547 $title = $author->display_name; 563 548 } 564 if ( !empty($author_name) ) {565 // We do a direct query here because we don't cache by nicename.566 $title = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM $wpdb->users WHERE user_nicename = %s", $author_name));567 }568 549 569 550 // If there's a month 570 if ( !empty($m) ) {551 if ( is_archive() && !empty($m) ) { 571 552 $my_year = substr($m, 0, 4); 572 553 $my_month = $wp_locale->get_month(substr($m, 4, 2)); 573 554 $my_day = intval(substr($m, 6, 2)); 574 555 $title = $my_year . ($my_month ? $t_sep . $my_month : "") . ($my_day ? $t_sep . $my_day : ""); 575 556 } 576 557 577 if ( !empty($year) ) { 558 // If there's a year 559 if ( is_archive() && !empty($year) ) { 578 560 $title = $year; 579 561 if ( !empty($monthnum) ) 580 562 $title .= $t_sep . $wp_locale->get_month($monthnum); … … 582 564 $title .= $t_sep . zeroise($day, 2); 583 565 } 584 566 585 // If there is a post 586 if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) { 587 $post = $wp_query->get_queried_object(); 588 $title = apply_filters( 'single_post_title', $post->post_title ); 589 } 590 591 // If there's a taxonomy 592 if ( is_tax() ) { 593 $taxonomy = get_query_var( 'taxonomy' ); 594 $tax = get_taxonomy( $taxonomy ); 595 $term = $wp_query->get_queried_object(); 596 $term = $term->name; 597 $title = $tax->labels->name . $t_sep . $term; 598 } 599 600 //If it's a search 567 // If it's a search 601 568 if ( is_search() ) { 602 569 /* translators: 1: separator, 2: search phrase */ 603 570 $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search)); 604 571 } 605 572 573 // If it's a 404 page 606 574 if ( is_404() ) { 607 575 $title = __('Page not found'); 608 576 } … … 684 652 * @param bool $display Optional, default is true. Whether to display or retrieve title. 685 653 * @return string|null Title when retrieving, null when displaying or failure. 686 654 */ 687 function single_cat_title($prefix = '', $display = true ) { 688 global $wp_query; 689 690 if ( is_tag() ) 691 return single_tag_title($prefix, $display); 692 693 if ( !is_category() ) 694 return; 695 696 $cat = $wp_query->get_queried_object(); 697 $my_cat_name = apply_filters('single_cat_title', $cat->name); 698 if ( !empty($my_cat_name) ) { 699 if ( $display ) 700 echo $prefix . $my_cat_name; 701 else 702 return $my_cat_name; 703 } 655 function single_cat_title( $prefix = '', $display = true ) { 656 return single_term_title( $prefix, $display ); 704 657 } 705 658 706 659 /** … … 720 673 * @param bool $display Optional, default is true. Whether to display or retrieve title. 721 674 * @return string|null Title when retrieving, null when displaying or failure. 722 675 */ 723 function single_tag_title($prefix = '', $display = true ) { 676 function single_tag_title( $prefix = '', $display = true ) { 677 return single_term_title( $prefix, $display ); 678 } 679 680 /** 681 * Display or retrieve page title for taxonomy term archive. 682 * 683 * Useful for taxonomy term template files for displaying the taxonomy term page title. 684 * It has less overhead than {@link wp_title()}, because of its limited implementation. 685 * 686 * It does not support placing the separator after the title, but by leaving the 687 * prefix parameter empty, you can set the title separator manually. The prefix 688 * does not automatically place a space between the prefix, so if there should 689 * be a space, the parameter value will need to have it at the end. 690 * 691 * @since 3.1.0 692 * 693 * @param string $prefix Optional. What to display before the title. 694 * @param bool $display Optional, default is true. Whether to display or retrieve title. 695 * @return string|null Title when retrieving, null when displaying or failure. 696 */ 697 function single_term_title( $prefix = '', $display = true ) { 724 698 global $wp_query; 725 if ( !is_tag() ) 699 700 $term = $wp_query->get_queried_object(); 701 702 if ( !$term ) 726 703 return; 727 704 728 $tag = $wp_query->get_queried_object(); 705 if ( is_category() ) 706 $term_name = apply_filters('single_cat_title', $term->name); 707 elseif ( is_tag() ) 708 $term_name = apply_filters('single_tag_title', $term->name); 709 elseif ( is_term() ) 710 $term_name = apply_filters('single_term_title', $term->name); 711 else 712 return; 729 713 730 if ( ! $tag)714 if ( empty($term_name) ) 731 715 return; 732 716 733 $my_tag_name = apply_filters('single_tag_title', $tag->name); 734 if ( !empty($my_tag_name) ) { 735 if ( $display ) 736 echo $prefix . $my_tag_name; 737 else 738 return $my_tag_name; 739 } 717 if ( $display ) 718 echo $prefix . $term_name; 719 else 720 return $term_name; 740 721 } 741 722 742 723 /**