Make WordPress Core

Ticket #12370: 12370.001.diff

File 12370.001.diff, 12.6 KB (added by aaroncampbell, 15 years ago)
  • wp-content/themes/twentyten/functions.php

     
    189189}
    190190endif;
    191191
    192 if ( ! function_exists( 'twentyten_the_page_number' ) ) :
    193192/**
    194  * Prints the page number currently being browsed, with a vertical bar before it.
    195  *
    196  * Used in Twenty Ten's header.php to add the page number to the <title> HTML tag.
    197  *
    198  * @since 3.0.0
    199  */
    200 function twentyten_the_page_number() {
    201         global $paged; // Contains page number.
    202         if ( $paged >= 2 )
    203                 echo ' | ' . sprintf( __( 'Page %s' , 'twentyten' ), $paged );
    204 }
    205 endif;
    206 
    207 /**
    208193 * Sets the post excerpt length to 40 characters.
    209194 *
    210195 * To override this length in a child theme, remove the filter and add your own
  • wp-content/themes/twentyten/header.php

     
    1414<html <?php language_attributes(); ?>>
    1515<head>
    1616        <meta charset="<?php bloginfo( 'charset' ); ?>" />
    17         <title><?php
    18         // Returns the title based on the type of page being viewed
    19                 if ( is_single() ) {
    20                         single_post_title(); echo ' | '; bloginfo( 'name' );
    21                 } elseif ( is_home() || is_front_page() ) {
    22                         bloginfo( 'name' );
    23                         if( get_bloginfo( 'description' ) )
    24                                 echo ' | ' ; bloginfo( 'description' );
    25                         twentyten_the_page_number();
    26                 } elseif ( is_page() ) {
    27                         single_post_title( '' ); echo ' | '; bloginfo( 'name' );
    28                 } elseif ( is_search() ) {
    29                         printf( __( 'Search results for "%s"', 'twentyten' ), esc_html( $s ) ); twentyten_the_page_number(); echo ' | '; bloginfo( 'name' );
    30                 } elseif ( is_404() ) {
    31                         _e( 'Not Found', 'twentyten' ); echo ' | '; bloginfo( 'name' );
    32                 } else {
    33                         wp_title( '' ); echo ' | '; bloginfo( 'name' ); twentyten_the_page_number();
    34                 }
    35         ?></title>
     17        <title><?php wp_title( '|' ); ?></title>
    3618        <link rel="profile" href="http://gmpg.org/xfn/11" />
    3719        <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
    3820        <?php if ( is_singular() && get_option('thread_comments') ) wp_enqueue_script( 'comment-reply' ); ?>
     
    5032                                <?php } else { ?>
    5133                                        <div id="site-title"><span><a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></span></div>
    5234                                <?php } ?>
    53                                
     35
    5436                                <div id="site-description"><?php bloginfo( 'description' ); ?></div>
    5537
    5638                                <?php
  • wp-includes/general-template.php

     
    500500 *
    501501 * @since 1.0.0
    502502 *
    503  * @param string $sep Optional, default is '&raquo;'. How to separate the various items within the page title.
     503 * @param string|array $args Optional. Override defaults.
    504504 * @param bool $display Optional, default is true. Whether to display or retrieve title.
    505  * @param string $seplocation Optional. Direction to display title, 'right'.
    506  * @return string|null String on retrieve, null when displaying.
     505 * @param string deprecated, use 'display' index in first param
     506 * @param string deprecated, use 'seplocation' index in first param
    507507 */
    508 function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
    509         global $wpdb, $wp_locale, $wp_query;
     508function wp_title( $args = array(), $display = true, $seplocation = '') {
     509        /**
     510         * This is for compatability. The first parameter used to be a string used
     511         * as a separator.
     512         */
     513        if ( !is_array($args) )
     514                $args = array(
     515                        'sep' => $args
     516                );
    510517
    511         $cat = get_query_var('cat');
    512         $tag = get_query_var('tag_id');
    513         $category_name = get_query_var('category_name');
    514         $author = get_query_var('author');
    515         $author_name = get_query_var('author_name');
    516         $m = get_query_var('m');
    517         $year = get_query_var('year');
    518         $monthnum = get_query_var('monthnum');
    519         $day = get_query_var('day');
    520         $search = get_query_var('s');
    521         $title = '';
     518        $defaults = array(
     519                'before' => '',
     520                'after' => '',
     521                'sep' => '&raquo;',
     522                'display' => true,
     523                'seplocation' => ''
     524        );
    522525
    523         $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
     526        $r = wp_parse_args( $args, $defaults );
    524527
    525         // If there's a category
    526         if ( !empty($cat) ) {
    527                         // category exclusion
    528                         if ( !stristr($cat,'-') )
    529                                 $title = apply_filters('single_cat_title', get_the_category_by_ID($cat));
    530         } elseif ( !empty($category_name) ) {
    531                 if ( stristr($category_name,'/') ) {
    532                                 $category_name = explode('/',$category_name);
    533                                 if ( $category_name[count($category_name)-1] )
    534                                         $category_name = $category_name[count($category_name)-1]; // no trailing slash
    535                                 else
    536                                         $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
    537                 }
    538                 $cat = get_term_by('slug', $category_name, 'category', OBJECT, 'display');
    539                 if ( $cat )
    540                         $title = apply_filters('single_cat_title', $cat->name);
    541         }
     528        // Used to support deprecated parameters
     529        if ( '' != $display && empty( $r['display'] ) )
     530                $r['display'] = $display;
    542531
    543         if ( !empty($tag) ) {
    544                 $tag = get_term($tag, 'post_tag', OBJECT, 'display');
    545                 if ( is_wp_error( $tag ) )
    546                         return $tag;
    547                 if ( ! empty($tag->name) )
    548                         $title = apply_filters('single_tag_title', $tag->name);
    549         }
     532        if ( '' != $seplocation && empty( $r['seplocation'] ) )
     533                $r['seplocation'] = $seplocation;
    550534
    551         // If there's an author
    552         if ( !empty($author) ) {
    553                 $title = get_userdata($author);
    554                 $title = $title->display_name;
    555         }
    556         if ( !empty($author_name) ) {
    557                 // We do a direct query here because we don't cache by nicename.
    558                 $title = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM $wpdb->users WHERE user_nicename = %s", $author_name));
    559         }
     535        // Allow plugins/themes to override the default wp_title functionality.
     536        $title = apply_filters( 'pre_wp_title', '', $r );
     537        if ( !empty( $title ) ) {
     538                $title = apply_filters('wp_title', $title, $r['sep'], $r['seplocation']);
    560539
    561         // If there's a month
    562         if ( !empty($m) ) {
    563                 $my_year = substr($m, 0, 4);
    564                 $my_month = $wp_locale->get_month(substr($m, 4, 2));
    565                 $my_day = intval(substr($m, 6, 2));
    566                 $title = $my_year . ($my_month ? $t_sep . $my_month : "") . ($my_day ? $t_sep . $my_day : "");
     540                // Send it out
     541                if ( $r['display'] )
     542                        echo $title;
     543                else
     544                        return $title;
    567545        }
    568546
    569         if ( !empty($year) ) {
    570                 $title = $year;
    571                 if ( !empty($monthnum) )
    572                         $title .= $t_sep . $wp_locale->get_month($monthnum);
    573                 if ( !empty($day) )
    574                         $title .= $t_sep . zeroise($day, 2);
    575         }
     547        global $wpdb, $wp_locale, $wp_query;
    576548
    577         // If there is a post
    578         if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
    579                 $post = $wp_query->get_queried_object();
    580                 $title = apply_filters( 'single_post_title', $post->post_title );
    581         }
     549        $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
    582550
    583         // If there's a taxonomy
    584         if ( is_tax() ) {
    585                 $taxonomy = get_query_var( 'taxonomy' );
    586                 $tax = get_taxonomy( $taxonomy );
    587                 $tax = $tax->label;
    588                 $term = $wp_query->get_queried_object();
    589                 $term = $term->name;
    590                 $title = $tax . $t_sep . $term;
    591         }
     551        if ( is_home() || is_front_page() ) {
     552                $title = get_bloginfo( 'name', 'display' );
     553                if( get_bloginfo( 'description' ) )
     554                        $title .= " {$t_sep} " . get_bloginfo( 'description', 'display' );
     555                $title .= get_the_page_number_title( $t_sep );
     556        } elseif ( is_single() || is_page() ) {
     557                $title = single_post_title( '', false) . " {$t_sep} " . get_bloginfo( 'name', 'display' );
     558        } elseif ( is_search() ) {
     559                /* translators: %s is search phrase */
     560                $title = sprintf( __( 'Search results for "%s"' ), get_search_query() );
     561                $title .= get_the_page_number_title( $t_sep ) . " {$t_sep} " . get_bloginfo( 'name', 'display' );
     562        } elseif ( is_404() ) {
     563                $title = __( 'Not Found' ) . " {$t_sep} " . get_bloginfo( 'name', 'display' );
     564        } else {
     565                /**
     566                 * Everything in this else gets the blog name and page number appended to the title
     567                 */
     568                if ( is_tax() ) {
     569                        $taxonomy = get_query_var( 'taxonomy' );
     570                        $tax = get_taxonomy( $taxonomy );
     571                        $tax = $tax->label;
     572                        $term = $wp_query->get_queried_object();
     573                        $term = $term->name;
     574                        $title = $tax . $t_sep . $term;
     575                } elseif ( get_query_var('year') ) {
     576                        $title = get_query_var('year');
     577                        $monthnum = get_query_var('monthnum');
     578                        $day = get_query_var('day');
     579                        if ( !empty($monthnum) )
     580                                $title .= $t_sep . $wp_locale->get_month($monthnum);
     581                        if ( !empty($day) )
     582                                $title .= $t_sep . zeroise($day, 2);
     583                } elseif ( get_query_var('m') ) {
     584                        $m = get_query_var('m');
     585                        $my_year = substr($m, 0, 4);
     586                        $my_month = $wp_locale->get_month(substr($m, 4, 2));
     587                        $my_day = intval(substr($m, 6, 2));
     588                        $title = $my_year . ($my_month ? $t_sep . $my_month : "") . ($my_day ? $t_sep . $my_day : "");
     589                } elseif ( get_query_var('author_name') ) {
     590                        $author_name = get_query_var('author_name');
     591                        // We do a direct query here because we don't cache by nicename.
     592                        $title = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM $wpdb->users WHERE user_nicename = %s", $author_name));
     593                } elseif ( get_query_var('author') ) {
     594                        $author = get_query_var('author');
     595                        $title = get_userdata($author);
     596                        $title = $title->display_name;
     597                } elseif ( get_query_var('tag_id') ) {
     598                        $tag = get_query_var('tag_id');
     599                        $tag = get_term($tag, 'post_tag', OBJECT, 'display');
     600                        if ( is_wp_error( $tag ) )
     601                                return $tag;
     602                        if ( ! empty($tag->name) )
     603                                $title = apply_filters('single_tag_title', $tag->name);
    592604
    593         //If it's a search
    594         if ( is_search() ) {
    595                 /* translators: 1: separator, 2: search phrase */
    596                 $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
    597         }
     605                } else {
     606                        $cat = get_query_var('cat');
     607                        $category_name = get_query_var('category_name');
    598608
    599         if ( is_404() ) {
    600                 $title = __('Page not found');
     609                        // If there's a category
     610                        if ( !empty($cat) ) {
     611                                        // category exclusion
     612                                        if ( !stristr($cat,'-') )
     613                                                $title = apply_filters('single_cat_title', get_the_category_by_ID($cat));
     614                        } elseif ( !empty($category_name) ) {
     615                                if ( stristr($category_name,'/') ) {
     616                                                $category_name = explode('/',$category_name);
     617                                                if ( $category_name[count($category_name)-1] )
     618                                                        $category_name = $category_name[count($category_name)-1]; // no trailing slash
     619                                                else
     620                                                        $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
     621                                }
     622                                $cat = get_term_by('slug', $category_name, 'category', OBJECT, 'display');
     623                                if ( $cat )
     624                                        $title = apply_filters('single_cat_title', $cat->name);
     625                        }
     626                }
     627
     628                if ( !empty( $title ) )
     629                        $title .= " {$t_sep} ";
     630                $title .= get_bloginfo( 'description', 'display' ) . get_the_page_number_title( $t_sep );
    601631        }
    602632
    603         $prefix = '';
    604         if ( !empty($title) )
    605                 $prefix = " $sep ";
    606 
    607         // Determines position of the separator and direction of the breadcrumb
    608         if ( 'right' == $seplocation ) { // sep on right, so reverse the order
     633        // Determines position of the separator and direction of the breadcrumb
     634        if ( 'right' == $r['seplocation'] ) { // sep on right, so reverse the order
    609635                $title_array = explode( $t_sep, $title );
    610636                $title_array = array_reverse( $title_array );
    611                 $title = implode( " $sep ", $title_array ) . $prefix;
     637                $title = implode( " {$r['sep']} ", $title_array );
    612638        } else {
    613639                $title_array = explode( $t_sep, $title );
    614                 $title = $prefix . implode( " $sep ", $title_array );
     640                $title = implode( " {$r['sep']} ", $title_array );
    615641        }
    616642
    617         $title = apply_filters('wp_title', $title, $sep, $seplocation);
     643        $title = apply_filters('wp_title', $title, $r['sep'], $r['seplocation'], $r);
    618644
    619645        // Send it out
    620         if ( $display )
     646        if ( $r['display'] )
    621647                echo $title;
    622648        else
    623649                return $title;
     
    625651}
    626652
    627653/**
     654 * Retrieve the page number currently being browsed
     655 *
     656 * Used in wp_title to add the page number to the returned title.
     657 *
     658 * @see wp_title()
     659 *
     660 * @return string Empty if on page one, " | Page #" if on page 2 or greater
     661 *
     662 * @since 3.0.0
     663 */
     664function get_the_page_number_title( $sep = '|' ) {
     665        $page = get_the_page_number();
     666        if ( $page < 2 )
     667                return '';
     668        return " {$sep} " . sprintf( __( 'Page %d' ), $page );
     669}
     670
     671/**
     672 * Retrieve the page number currently being browsed
     673 *
     674 * @return int Page number
     675 *
     676 * @since 3.0.0
     677 */
     678function get_the_page_number() {
     679        global $paged; // Contains page number.
     680        return absint( $paged );
     681}
     682
     683
     684/**
    628685 * Display or retrieve page title for post.
    629686 *
    630687 * This is optimized for single.php template file for displaying the post title.