| [ Root ] [ Search ] [ Index ] |
PHP Cross Reference of WordPress 3.0Provided by Yoast |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * TwentyTen functions and definitions 4 * 5 * Sets up the theme and provides some helper functions. Some helper functions 6 * are used in the theme as custom template tags. Others are attached to action and 7 * filter hooks in WordPress to change core functionality. 8 * 9 * The first function, twentyten_setup(), sets up the theme by registering support 10 * for various features in WordPress, such as post thumbnails, navigation menus, and the like. 11 * 12 * When using a child theme (see http://codex.wordpress.org/Theme_Development and 13 * http://codex.wordpress.org/Child_Themes), you can override certain functions 14 * (those wrapped in a function_exists() call) by defining them first in your child theme's 15 * functions.php file. The child theme's functions.php file is included before the parent 16 * theme's file, so the child theme functions would be used. 17 * 18 * Functions that are not pluggable (not wrapped in function_exists()) are instead attached 19 * to a filter or action hook. The hook can be removed by using remove_action() or 20 * remove_filter() and you can attach your own function to the hook. 21 * 22 * We can remove the parent theme's hook only after it is attached, which means we need to 23 * wait until setting up the child theme: 24 * 25 * <code> 26 * add_action( 'after_setup_theme', 'my_child_theme_setup' ); 27 * function my_child_theme_setup() { 28 * // We are providing our own filter for excerpt_length (or using the unfiltered value) 29 * remove_filter( 'excerpt_length', 'twentyten_excerpt_length' ); 30 * ... 31 * } 32 * </code> 33 * 34 * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API. 35 * 36 * @package WordPress 37 * @subpackage Twenty_Ten 38 * @since Twenty Ten 1.0 39 */ 40 41 /** 42 * Set the content width based on the theme's design and stylesheet. 43 * 44 * Used to set the width of images and content. Should be equal to the width the theme 45 * is designed for, generally via the style.css stylesheet. 46 */ 47 if ( ! isset( $content_width ) ) 48 $content_width = 640; 49 50 /** Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */ 51 add_action( 'after_setup_theme', 'twentyten_setup' ); 52 53 if ( ! function_exists( 'twentyten_setup' ) ): 54 /** 55 * Sets up theme defaults and registers support for various WordPress features. 56 * 57 * Note that this function is hooked into the after_setup_theme hook, which runs 58 * before the init hook. The init hook is too late for some features, such as indicating 59 * support post thumbnails. 60 * 61 * To override twentyten_setup() in a child theme, add your own twentyten_setup to your child theme's 62 * functions.php file. 63 * 64 * @uses add_theme_support() To add support for post thumbnails and automatic feed links. 65 * @uses register_nav_menus() To add support for navigation menus. 66 * @uses add_custom_background() To add support for a custom background. 67 * @uses add_editor_style() To style the visual editor. 68 * @uses load_theme_textdomain() For translation/localization support. 69 * @uses add_custom_image_header() To add support for a custom header. 70 * @uses register_default_headers() To register the default custom header images provided with the theme. 71 * @uses set_post_thumbnail_size() To set a custom post thumbnail size. 72 * 73 * @since Twenty Ten 1.0 74 */ 75 function twentyten_setup() { 76 77 // This theme styles the visual editor with editor-style.css to match the theme style. 78 add_editor_style(); 79 80 // This theme uses post thumbnails 81 add_theme_support( 'post-thumbnails' ); 82 83 // Add default posts and comments RSS feed links to head 84 add_theme_support( 'automatic-feed-links' ); 85 86 // Make theme available for translation 87 // Translations can be filed in the /languages/ directory 88 load_theme_textdomain( 'twentyten', TEMPLATEPATH . '/languages' ); 89 90 $locale = get_locale(); 91 $locale_file = TEMPLATEPATH . "/languages/$locale.php"; 92 if ( is_readable( $locale_file ) ) 93 require_once( $locale_file ); 94 95 // This theme uses wp_nav_menu() in one location. 96 register_nav_menus( array( 97 'primary' => __( 'Primary Navigation', 'twentyten' ), 98 ) ); 99 100 // This theme allows users to set a custom background 101 add_custom_background(); 102 103 // Your changeable header business starts here 104 define( 'HEADER_TEXTCOLOR', '' ); 105 // No CSS, just IMG call. The %s is a placeholder for the theme template directory URI. 106 define( 'HEADER_IMAGE', '%s/images/headers/path.jpg' ); 107 108 // The height and width of your custom header. You can hook into the theme's own filters to change these values. 109 // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values. 110 define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) ); 111 define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) ); 112 113 // We'll be using post thumbnails for custom header images on posts and pages. 114 // We want them to be 940 pixels wide by 198 pixels tall. 115 // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php. 116 set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); 117 118 // Don't support text inside the header image. 119 define( 'NO_HEADER_TEXT', true ); 120 121 // Add a way for the custom header to be styled in the admin panel that controls 122 // custom headers. See twentyten_admin_header_style(), below. 123 add_custom_image_header( '', 'twentyten_admin_header_style' ); 124 125 // ... and thus ends the changeable header business. 126 127 // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. 128 register_default_headers( array( 129 'berries' => array( 130 'url' => '%s/images/headers/berries.jpg', 131 'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg', 132 /* translators: header image description */ 133 'description' => __( 'Berries', 'twentyten' ) 134 ), 135 'cherryblossom' => array( 136 'url' => '%s/images/headers/cherryblossoms.jpg', 137 'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg', 138 /* translators: header image description */ 139 'description' => __( 'Cherry Blossoms', 'twentyten' ) 140 ), 141 'concave' => array( 142 'url' => '%s/images/headers/concave.jpg', 143 'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg', 144 /* translators: header image description */ 145 'description' => __( 'Concave', 'twentyten' ) 146 ), 147 'fern' => array( 148 'url' => '%s/images/headers/fern.jpg', 149 'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg', 150 /* translators: header image description */ 151 'description' => __( 'Fern', 'twentyten' ) 152 ), 153 'forestfloor' => array( 154 'url' => '%s/images/headers/forestfloor.jpg', 155 'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg', 156 /* translators: header image description */ 157 'description' => __( 'Forest Floor', 'twentyten' ) 158 ), 159 'inkwell' => array( 160 'url' => '%s/images/headers/inkwell.jpg', 161 'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg', 162 /* translators: header image description */ 163 'description' => __( 'Inkwell', 'twentyten' ) 164 ), 165 'path' => array( 166 'url' => '%s/images/headers/path.jpg', 167 'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg', 168 /* translators: header image description */ 169 'description' => __( 'Path', 'twentyten' ) 170 ), 171 'sunset' => array( 172 'url' => '%s/images/headers/sunset.jpg', 173 'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg', 174 /* translators: header image description */ 175 'description' => __( 'Sunset', 'twentyten' ) 176 ) 177 ) ); 178 } 179 endif; 180 181 if ( ! function_exists( 'twentyten_admin_header_style' ) ) : 182 /** 183 * Styles the header image displayed on the Appearance > Header admin panel. 184 * 185 * Referenced via add_custom_image_header() in twentyten_setup(). 186 * 187 * @since Twenty Ten 1.0 188 */ 189 function twentyten_admin_header_style() { 190 ?> 191 <style type="text/css"> 192 /* Shows the same border as on front end */ 193 #headimg { 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 */ 201 </style> 202 <?php 203 } 204 endif; 205 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 */ 225 function twentyten_filter_wp_title( $title, $separator ) { 226 // Don't affect wp_title() calls in feeds. 227 if ( is_feed() ) 228 return $title; 229 230 // The $paged global variable contains the page number of a listing of posts. 231 // The $page global variable contains the page number of a single post that is paged. 232 // We'll display whichever one applies, if we're not looking at the first page. 233 global $paged, $page; 234 235 if ( is_search() ) { 236 // If we're a search, let's start over: 237 $title = sprintf( __( 'Search results for %s', 'twentyten' ), '"' . get_search_query() . '"' ); 238 // Add a page number if we're on page 2 or more: 239 if ( $paged >= 2 ) 240 $title .= " $separator " . sprintf( __( 'Page %s', 'twentyten' ), $paged ); 241 // Add the site name to the end: 242 $title .= " $separator " . get_bloginfo( 'name', 'display' ); 243 // We're done. Let's send the new title back to wp_title(): 244 return $title; 245 } 246 247 // Otherwise, let's start by adding the site name to the end: 248 $title .= get_bloginfo( 'name', 'display' ); 249 250 // If we have a site description and we're on the home/front page, add the description: 251 $site_description = get_bloginfo( 'description', 'display' ); 252 if ( $site_description && ( is_home() || is_front_page() ) ) 253 $title .= " $separator " . $site_description; 254 255 // Add a page number if necessary: 256 if ( $paged >= 2 || $page >= 2 ) 257 $title .= " $separator " . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) ); 258 259 // Return the new title to wp_title(): 260 return $title; 261 } 262 add_filter( 'wp_title', 'twentyten_filter_wp_title', 10, 2 ); 263 264 /** 265 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link. 266 * 267 * To override this in a child theme, remove the filter and optionally add 268 * your own function tied to the wp_page_menu_args filter hook. 269 * 270 * @since Twenty Ten 1.0 271 */ 272 function twentyten_page_menu_args( $args ) { 273 $args['show_home'] = true; 274 return $args; 275 } 276 add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' ); 277 278 /** 279 * Sets the post excerpt length to 40 characters. 280 * 281 * To override this length in a child theme, remove the filter and add your own 282 * function tied to the excerpt_length filter hook. 283 * 284 * @since Twenty Ten 1.0 285 * @return int 286 */ 287 function twentyten_excerpt_length( $length ) { 288 return 40; 289 } 290 add_filter( 'excerpt_length', 'twentyten_excerpt_length' ); 291 292 /** 293 * Returns a "Continue Reading" link for excerpts 294 * 295 * @since Twenty Ten 1.0 296 * @return string "Continue Reading" link 297 */ 298 function twentyten_continue_reading_link() { 299 return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyten' ) . '</a>'; 300 } 301 302 /** 303 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link(). 304 * 305 * To override this in a child theme, remove the filter and add your own 306 * function tied to the excerpt_more filter hook. 307 * 308 * @since Twenty Ten 1.0 309 * @return string An ellipsis 310 */ 311 function twentyten_auto_excerpt_more( $more ) { 312 return ' …' . twentyten_continue_reading_link(); 313 } 314 add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' ); 315 316 /** 317 * Adds a pretty "Continue Reading" link to custom post excerpts. 318 * 319 * To override this link in a child theme, remove the filter and add your own 320 * function tied to the get_the_excerpt filter hook. 321 * 322 * @since Twenty Ten 1.0 323 * @return string Excerpt with a pretty "Continue Reading" link 324 */ 325 function twentyten_custom_excerpt_more( $output ) { 326 if ( has_excerpt() && ! is_attachment() ) { 327 $output .= twentyten_continue_reading_link(); 328 } 329 return $output; 330 } 331 add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' ); 332 333 /** 334 * Remove inline styles printed when the gallery shortcode is used. 335 * 336 * Galleries are styled by the theme in Twenty Ten's style.css. 337 * 338 * @since Twenty Ten 1.0 339 * @return string The gallery style filter, with the styles themselves removed. 340 */ 341 function twentyten_remove_gallery_css( $css ) { 342 return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css ); 343 } 344 add_filter( 'gallery_style', 'twentyten_remove_gallery_css' ); 345 346 if ( ! function_exists( 'twentyten_comment' ) ) : 347 /** 348 * Template for comments and pingbacks. 349 * 350 * To override this walker in a child theme without modifying the comments template 351 * simply create your own twentyten_comment(), and that function will be used instead. 352 * 353 * Used as a callback by wp_list_comments() for displaying the comments. 354 * 355 * @since Twenty Ten 1.0 356 */ 357 function twentyten_comment( $comment, $args, $depth ) { 358 $GLOBALS['comment'] = $comment; 359 switch ( $comment->comment_type ) : 360 case '' : 361 ?> 362 <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"> 363 <div id="comment-<?php comment_ID(); ?>"> 364 <div class="comment-author vcard"> 365 <?php echo get_avatar( $comment, 40 ); ?> 366 <?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?> 367 </div><!-- .comment-author .vcard --> 368 <?php if ( $comment->comment_approved == '0' ) : ?> 369 <em><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em> 370 <br /> 371 <?php endif; ?> 372 373 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"> 374 <?php 375 /* translators: 1: date, 2: time */ 376 printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); 377 ?> 378 </div><!-- .comment-meta .commentmetadata --> 379 380 <div class="comment-body"><?php comment_text(); ?></div> 381 382 <div class="reply"> 383 <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> 384 </div><!-- .reply --> 385 </div><!-- #comment-## --> 386 387 <?php 388 break; 389 case 'pingback' : 390 case 'trackback' : 391 ?> 392 <li class="post pingback"> 393 <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'twentyten'), ' ' ); ?></p> 394 <?php 395 break; 396 endswitch; 397 } 398 endif; 399 400 /** 401 * Register widgetized areas, including two sidebars and four widget-ready columns in the footer. 402 * 403 * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own 404 * function tied to the init hook. 405 * 406 * @since Twenty Ten 1.0 407 * @uses register_sidebar 408 */ 409 function twentyten_widgets_init() { 410 // Area 1, located at the top of the sidebar. 411 register_sidebar( array( 412 'name' => __( 'Primary Widget Area', 'twentyten' ), 413 'id' => 'primary-widget-area', 414 'description' => __( 'The primary widget area', 'twentyten' ), 415 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 416 'after_widget' => '</li>', 417 'before_title' => '<h3 class="widget-title">', 418 'after_title' => '</h3>', 419 ) ); 420 421 // Area 2, located below the Primary Widget Area in the sidebar. Empty by default. 422 register_sidebar( array( 423 'name' => __( 'Secondary Widget Area', 'twentyten' ), 424 'id' => 'secondary-widget-area', 425 'description' => __( 'The secondary widget area', 'twentyten' ), 426 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 427 'after_widget' => '</li>', 428 'before_title' => '<h3 class="widget-title">', 429 'after_title' => '</h3>', 430 ) ); 431 432 // Area 3, located in the footer. Empty by default. 433 register_sidebar( array( 434 'name' => __( 'First Footer Widget Area', 'twentyten' ), 435 'id' => 'first-footer-widget-area', 436 'description' => __( 'The first footer widget area', 'twentyten' ), 437 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 438 'after_widget' => '</li>', 439 'before_title' => '<h3 class="widget-title">', 440 'after_title' => '</h3>', 441 ) ); 442 443 // Area 4, located in the footer. Empty by default. 444 register_sidebar( array( 445 'name' => __( 'Second Footer Widget Area', 'twentyten' ), 446 'id' => 'second-footer-widget-area', 447 'description' => __( 'The second footer widget area', 'twentyten' ), 448 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 449 'after_widget' => '</li>', 450 'before_title' => '<h3 class="widget-title">', 451 'after_title' => '</h3>', 452 ) ); 453 454 // Area 5, located in the footer. Empty by default. 455 register_sidebar( array( 456 'name' => __( 'Third Footer Widget Area', 'twentyten' ), 457 'id' => 'third-footer-widget-area', 458 'description' => __( 'The third footer widget area', 'twentyten' ), 459 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 460 'after_widget' => '</li>', 461 'before_title' => '<h3 class="widget-title">', 462 'after_title' => '</h3>', 463 ) ); 464 465 // Area 6, located in the footer. Empty by default. 466 register_sidebar( array( 467 'name' => __( 'Fourth Footer Widget Area', 'twentyten' ), 468 'id' => 'fourth-footer-widget-area', 469 'description' => __( 'The fourth footer widget area', 'twentyten' ), 470 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 471 'after_widget' => '</li>', 472 'before_title' => '<h3 class="widget-title">', 473 'after_title' => '</h3>', 474 ) ); 475 } 476 /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */ 477 add_action( 'widgets_init', 'twentyten_widgets_init' ); 478 479 /** 480 * Removes the default styles that are packaged with the Recent Comments widget. 481 * 482 * To override this in a child theme, remove the filter and optionally add your own 483 * function tied to the widgets_init action hook. 484 * 485 * @since Twenty Ten 1.0 486 */ 487 function twentyten_remove_recent_comments_style() { 488 global $wp_widget_factory; 489 remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) ); 490 } 491 add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' ); 492 493 if ( ! function_exists( 'twentyten_posted_on' ) ) : 494 /** 495 * Prints HTML with meta information for the current post—date/time and author. 496 * 497 * @since Twenty Ten 1.0 498 */ 499 function twentyten_posted_on() { 500 printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ), 501 'meta-prep meta-prep-author', 502 sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>', 503 get_permalink(), 504 esc_attr( get_the_time() ), 505 get_the_date() 506 ), 507 sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>', 508 get_author_posts_url( get_the_author_meta( 'ID' ) ), 509 sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ), 510 get_the_author() 511 ) 512 ); 513 } 514 endif; 515 516 if ( ! function_exists( 'twentyten_posted_in' ) ) : 517 /** 518 * Prints HTML with meta information for the current post (category, tags and permalink). 519 * 520 * @since Twenty Ten 1.0 521 */ 522 function twentyten_posted_in() { 523 // Retrieves tag list of current post, separated by commas. 524 $tag_list = get_the_tag_list( '', ', ' ); 525 if ( $tag_list ) { 526 $posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' ); 527 } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) { 528 $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' ); 529 } else { 530 $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' ); 531 } 532 // Prints the string, replacing the placeholders. 533 printf( 534 $posted_in, 535 get_the_category_list( ', ' ), 536 $tag_list, 537 get_permalink(), 538 the_title_attribute( 'echo=0' ) 539 ); 540 } 541 endif;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Oct 14 05:11:12 2010 | Cross-referenced by PHPXref 0.7 |