WordPress.org

Make WordPress Core

Changeset 15195


Ignore:
Timestamp:
06/10/10 18:26:53 (4 years ago)
Author:
nacin
Message:

Use wp_title() proper in Twenty Ten, and move the janky stuff to a filter. see #13751.

Location:
trunk/wp-content/themes/twentyten
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/twentyten/functions.php

    r15193 r15195  
    192192/* Shows the same border as on front end */ 
    193193#headimg { 
    194     border-bottom: 1px solid #000000; 
    195     border-top: 4px solid #000000; 
    196 } 
    197  
    198 /* If NO_HEADER_TEXT is false, you can style here the header text preview */ 
    199 #headimg #name { 
    200 } 
    201  
    202 #headimg #desc { 
    203 } 
     194    border-bottom: 1px solid #000; 
     195    border-top: 4px solid #000; 
     196} 
     197/* If NO_HEADER_TEXT is false, you would style the text with these selectors: 
     198    #headimg #name { } 
     199    #headimg #desc { } 
     200*/ 
    204201</style> 
    205202<?php 
     
    207204endif; 
    208205 
    209 if ( ! function_exists( 'twentyten_the_page_number' ) ) : 
    210 /** 
    211  * Prints the page number currently being browsed, with a vertical bar before it. 
    212  * 
    213  * Used in Twenty Ten's header.php to add the page number to the <title> HTML tag. 
    214  * 
    215  * @since Twenty Ten 1.0 
    216  */ 
    217 function twentyten_the_page_number() { 
    218     global $paged; // Contains page number. 
    219     if ( $paged >= 2 ) 
    220         echo ' | ' . sprintf( __( 'Page %s', 'twentyten' ), $paged ); 
    221 } 
    222 endif; 
     206/** 
     207 * Makes some changes to the <title> tag, by filtering the output of wp_title(). 
     208 * 
     209 * If we have a site description and we're viewing the home page or a blog posts 
     210 * page (when using a static front page), then we will add the site description. 
     211 * 
     212 * If we're viewing a search result, then we're going to recreate the title entirely. 
     213 * We're going to add page numbers to all titles as well, to the middle of a search 
     214 * result title and the end of all other titles. 
     215 * 
     216 * The site title also gets added to all titles. 
     217 * 
     218 * @since Twenty Ten 1.0 
     219 * 
     220 * @param string $title Title generated by wp_title() 
     221 * @param string $separator The separator passed to wp_title(). Twenty Ten uses a 
     222 *  vertical bar, "|", as a separator in header.php. 
     223 * @return string The new title, ready for the <title> tag. 
     224 */ 
     225function twentyten_filter_wp_title( $title, $separator ) { 
     226    // The $paged global variable contains the page number of a listing of posts. 
     227    // The $page global variable contains the page number of a single post that is paged. 
     228    // We'll display whichever one applies, if we're not looking at the first page. 
     229    global $paged, $page; 
     230 
     231    if ( is_search() ) { 
     232        // If we're a search, let's start over: 
     233        $title = sprintf( __( 'Search results for %s', 'twentyten' ), '"' . get_search_query() . '"' ); 
     234        // Add a page number if we're on page 2 or more: 
     235        if ( $paged >= 2 ) 
     236            $title .= " $separator " . sprintf( __( 'Page %s', 'twentyten' ), $paged ); 
     237        // Add the site name to the end: 
     238        $title .= " $separator " . get_bloginfo( 'name', 'display' ); 
     239        // We're done. Let's send the new title back to wp_title(): 
     240        return $title; 
     241    } 
     242 
     243    // Otherwise, let's start by adding the site name to the end: 
     244    $title .= get_bloginfo( 'name', 'display' ); 
     245 
     246    // If we have a site description and we're on the home/front page, add the description: 
     247    $site_description = get_bloginfo( 'description', 'display' ); 
     248    if ( $site_description && ( is_home() || is_front_page() ) ) 
     249        $title .= " $separator " . $site_description; 
     250 
     251    // Add a page number if necessary: 
     252    if ( $paged >= 2 || $page >= 2 ) 
     253        $title .= " $separator " . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) ); 
     254 
     255    // Return the new title to wp_title(): 
     256    return $title; 
     257} 
     258add_filter( 'wp_title', 'twentyten_filter_wp_title', 10, 2 ); 
    223259 
    224260/** 
  • trunk/wp-content/themes/twentyten/header.php

    r15082 r15195  
    1212<html <?php language_attributes(); ?>> 
    1313<head> 
    14     <meta charset="<?php bloginfo( 'charset' ); ?>" /> 
    15     <title> 
    16     <?php // Returns the title based on what is being viewed 
    17         if ( is_single() ) { // single posts 
    18             single_post_title(); echo ' | '; bloginfo( 'name' ); 
    19         // The home page or, if using a static front page, the blog posts page. 
    20         } elseif ( is_home() || is_front_page() ) { 
    21             bloginfo( 'name' ); 
    22             if( get_bloginfo( 'description' ) ) 
    23                 echo ' | ' ; bloginfo( 'description' ); 
    24             twentyten_the_page_number(); 
    25         } elseif ( is_page() ) { // WordPress Pages 
    26             single_post_title( '' ); echo ' | '; bloginfo( 'name' ); 
    27         } elseif ( is_search() ) { // Search results 
    28             printf( __( 'Search results for %s', 'twentyten' ), '"'.get_search_query().'"' ); twentyten_the_page_number(); echo ' | '; bloginfo( 'name' ); 
    29         } elseif ( is_404() ) {  // 404 (Not Found) 
    30             _e( 'Not Found', 'twentyten' ); echo ' | '; bloginfo( 'name' ); 
    31         } else { // Otherwise: 
    32             wp_title( '' ); echo ' | '; bloginfo( 'name' ); twentyten_the_page_number(); 
    33         } 
    34     ?> 
    35     </title> 
    36     <link rel="profile" href="http://gmpg.org/xfn/11" /> 
    37     <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" /> 
    38     <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" /> 
     14<meta charset="<?php bloginfo( 'charset' ); ?>" /> 
     15<title><?php 
     16    /* 
     17     * Print the <title> tag based on what is being viewed. 
     18     * We filter the output of wp_title() a bit -- see 
     19     * twentyten_filter_wp_title() in functions.php. 
     20     */ 
     21    wp_title( '|', true, 'right' ); 
     22 
     23    ?></title> 
     24<link rel="profile" href="http://gmpg.org/xfn/11" /> 
     25<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" /> 
     26<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" /> 
    3927<?php 
    4028    /* We add some JavaScript to pages with the comment form 
     
    4937     * as styles, scripts, and meta tags. 
    5038     */ 
    51  
    5239    wp_head(); 
    5340?> 
Note: See TracChangeset for help on using the changeset viewer.