| [ XREF Home ] [ Index ] |
PHP Cross Reference of WordPress TrunkProvided by Yoast |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Twenty Eleven 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, twentyeleven_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', 'twentyeleven_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_Eleven 38 * @since Twenty Eleven 1.0 39 */ 40 41 /** 42 * Set the content width based on the theme's design and stylesheet. 43 */ 44 if ( ! isset( $content_width ) ) 45 $content_width = 584; 46 47 /** 48 * Tell WordPress to run twentyeleven_setup() when the 'after_setup_theme' hook is run. 49 */ 50 add_action( 'after_setup_theme', 'twentyeleven_setup' ); 51 52 if ( ! function_exists( 'twentyeleven_setup' ) ): 53 /** 54 * Sets up theme defaults and registers support for various WordPress features. 55 * 56 * Note that this function is hooked into the after_setup_theme hook, which runs 57 * before the init hook. The init hook is too late for some features, such as indicating 58 * support post thumbnails. 59 * 60 * To override twentyeleven_setup() in a child theme, add your own twentyeleven_setup to your child theme's 61 * functions.php file. 62 * 63 * @uses load_theme_textdomain() For translation/localization support. 64 * @uses add_editor_style() To style the visual editor. 65 * @uses add_theme_support() To add support for post thumbnails, automatic feed links, and Post Formats. 66 * @uses register_nav_menus() To add support for navigation menus. 67 * @uses add_custom_background() To add support for a custom background. 68 * @uses add_custom_image_header() To add support for a custom header. 69 * @uses register_default_headers() To register the default custom header images provided with the theme. 70 * @uses set_post_thumbnail_size() To set a custom post thumbnail size. 71 * 72 * @since Twenty Eleven 1.0 73 */ 74 function twentyeleven_setup() { 75 76 /* Make Twenty Eleven available for translation. 77 * Translations can be added to the /languages/ directory. 78 * If you're building a theme based on Twenty Eleven, use a find and replace 79 * to change 'twentyeleven' to the name of your theme in all the template files. 80 */ 81 load_theme_textdomain( 'twentyeleven', TEMPLATEPATH . '/languages' ); 82 83 $locale = get_locale(); 84 $locale_file = TEMPLATEPATH . "/languages/$locale.php"; 85 if ( is_readable( $locale_file ) ) 86 require_once( $locale_file ); 87 88 // This theme styles the visual editor with editor-style.css to match the theme style. 89 add_editor_style(); 90 91 // Load up our theme options page and related code. 92 require( dirname( __FILE__ ) . '/inc/theme-options.php' ); 93 94 // Grab Twenty Eleven's Epherma widget. 95 require( dirname( __FILE__ ) . '/inc/widgets.php' ); 96 97 // Add default posts and comments RSS feed links to <head>. 98 add_theme_support( 'automatic-feed-links' ); 99 100 // This theme uses wp_nav_menu() in one location. 101 register_nav_menu( 'primary', __( 'Primary Menu', 'twentyeleven' ) ); 102 103 /** 104 * Add support for an Aside Post Format 105 */ 106 add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) ); 107 108 /** 109 * Add support for custom backgrounds 110 */ 111 add_custom_background(); 112 113 // This theme uses Feature Images for per-post/per-page Custom Header images 114 add_theme_support( 'post-thumbnails' ); 115 116 /** 117 * Add support for Custom Headers 118 */ 119 define( 'HEADER_TEXTCOLOR', '000' ); 120 121 // No CSS, just an IMG call. The %s is a placeholder for the theme template directory URI. 122 define( 'HEADER_IMAGE', '' ); // Leaving empty for random image rotation. 123 124 // The height and width of your custom header. You can hook into the theme's own filters to change these values. 125 // Add a filter to twentyeleven_header_image_width and twentyeleven_header_image_height to change these values. 126 define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyeleven_header_image_width', 1000 ) ); 127 define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyeleven_header_image_height', 288 ) ); 128 129 // We'll be using post thumbnails for custom header images on posts and pages. 130 // We want them to be 940 pixels wide by 198 pixels tall. 131 // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php. 132 set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); 133 134 // Add Twenty Eleven's custom image sizes 135 add_image_size( 'large-feature', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); // Used for large feature images 136 add_image_size( 'small-feature', 500, 300 ); // Used for featured posts if a large-feature doesn't exist 137 138 // Add a way for the custom header to be styled in the admin panel that controls 139 // custom headers. See twentyeleven_admin_header_style(), below. 140 add_custom_image_header( 'twentyeleven_header_style', 'twentyeleven_admin_header_style', 'twentyeleven_admin_header_image' ); 141 142 // ... and thus ends the changeable header business. 143 144 // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. 145 register_default_headers( array( 146 'wheel' => array( 147 'url' => '%s/images/headers/wheel.jpg', 148 'thumbnail_url' => '%s/images/headers/wheel-thumbnail.jpg', 149 /* translators: header image description */ 150 'description' => __( 'Wheel', 'twentyeleven' ) 151 ), 152 'shore' => array( 153 'url' => '%s/images/headers/shore.jpg', 154 'thumbnail_url' => '%s/images/headers/shore-thumbnail.jpg', 155 /* translators: header image description */ 156 'description' => __( 'Shore', 'twentyeleven' ) 157 ), 158 'trolley' => array( 159 'url' => '%s/images/headers/trolley.jpg', 160 'thumbnail_url' => '%s/images/headers/trolley-thumbnail.jpg', 161 /* translators: header image description */ 162 'description' => __( 'Trolley', 'twentyeleven' ) 163 ), 164 'pine-cone' => array( 165 'url' => '%s/images/headers/pine-cone.jpg', 166 'thumbnail_url' => '%s/images/headers/pine-cone-thumbnail.jpg', 167 /* translators: header image description */ 168 'description' => __( 'Pine Cone', 'twentyeleven' ) 169 ), 170 'chessboard' => array( 171 'url' => '%s/images/headers/chessboard.jpg', 172 'thumbnail_url' => '%s/images/headers/chessboard-thumbnail.jpg', 173 /* translators: header image description */ 174 'description' => __( 'Chessboard', 'twentyeleven' ) 175 ), 176 'lanterns' => array( 177 'url' => '%s/images/headers/lanterns.jpg', 178 'thumbnail_url' => '%s/images/headers/lanterns-thumbnail.jpg', 179 /* translators: header image description */ 180 'description' => __( 'Lanterns', 'twentyeleven' ) 181 ), 182 'willow' => array( 183 'url' => '%s/images/headers/willow.jpg', 184 'thumbnail_url' => '%s/images/headers/willow-thumbnail.jpg', 185 /* translators: header image description */ 186 'description' => __( 'Willow', 'twentyeleven' ) 187 ), 188 'hanoi' => array( 189 'url' => '%s/images/headers/hanoi.jpg', 190 'thumbnail_url' => '%s/images/headers/hanoi-thumbnail.jpg', 191 /* translators: header image description */ 192 'description' => __( 'Hanoi Plant', 'twentyeleven' ) 193 ) 194 ) ); 195 } 196 endif; // twentyeleven_setup 197 198 if ( ! function_exists( 'twentyeleven_header_style' ) ) : 199 /** 200 * Styles the header image and text displayed on the blog 201 * 202 * @since Twenty Eleven 1.0 203 */ 204 function twentyeleven_header_style() { 205 206 // If no custom options for text are set, let's bail 207 // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value 208 if ( HEADER_TEXTCOLOR == get_header_textcolor() ) 209 return; 210 // If we get this far, we have custom styles. Let's do this. 211 ?> 212 <style type="text/css"> 213 <?php 214 // Has the text been hidden? 215 if ( 'blank' == get_header_textcolor() ) : 216 ?> 217 #site-title, 218 #site-description { 219 position: absolute !important; 220 clip: rect(1px 1px 1px 1px); /* IE6, IE7 */ 221 clip: rect(1px, 1px, 1px, 1px); 222 } 223 <?php 224 // If the user has set a custom color for the text use that 225 else : 226 ?> 227 #site-title a, 228 #site-description { 229 color: #<?php echo get_header_textcolor(); ?> !important; 230 } 231 <?php endif; ?> 232 </style> 233 <?php 234 } 235 endif; // twentyeleven_header_style 236 237 if ( ! function_exists( 'twentyeleven_admin_header_style' ) ) : 238 /** 239 * Styles the header image displayed on the Appearance > Header admin panel. 240 * 241 * Referenced via add_custom_image_header() in twentyeleven_setup(). 242 * 243 * @since Twenty Eleven 1.0 244 */ 245 function twentyeleven_admin_header_style() { 246 ?> 247 <style type="text/css"> 248 .appearance_page_custom-header #headimg { 249 border: none; 250 } 251 #headimg h1, 252 #desc { 253 font-family: "Helvetica Neue", Arial, Helvetica, "Nimbus Sans L", sans-serif; 254 } 255 #headimg h1 { 256 margin: 0; 257 } 258 #headimg h1 a { 259 font-size: 32px; 260 line-height: 36px; 261 text-decoration: none; 262 } 263 #desc { 264 font-size: 14px; 265 line-height: 23px; 266 padding: 0 0 3em; 267 } 268 <?php 269 // If the user has set a custom color for the text use that 270 if ( get_header_textcolor() != HEADER_TEXTCOLOR ) : 271 ?> 272 #site-title a, 273 #site-description { 274 color: #<?php echo get_header_textcolor(); ?>; 275 } 276 <?php endif; ?> 277 #headimg img { 278 max-width: 1000px; 279 height: auto; 280 width: 100%; 281 } 282 </style> 283 <?php 284 } 285 endif; // twentyeleven_admin_header_style 286 287 if ( ! function_exists( 'twentyeleven_admin_header_image' ) ) : 288 /** 289 * Custom header image markup displayed on the Appearance > Header admin panel. 290 * 291 * Referenced via add_custom_image_header() in twentyeleven_setup(). 292 * 293 * @since Twenty Eleven 1.0 294 */ 295 function twentyeleven_admin_header_image() { ?> 296 <div id="headimg"> 297 <?php 298 if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) ) 299 $style = ' style="display:none;"'; 300 else 301 $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"'; 302 ?> 303 <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo home_url( '/' ); ?>"><?php bloginfo( 'name' ); ?></a></h1> 304 <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div> 305 <?php $header_image = get_header_image(); 306 if ( ! empty( $header_image ) ) : ?> 307 <img src="<?php echo esc_url( $header_image ); ?>" alt="" /> 308 <?php endif; ?> 309 </div> 310 <?php } 311 endif; // twentyeleven_admin_header_image 312 313 /** 314 * Sets the post excerpt length to 40 words. 315 * 316 * To override this length in a child theme, remove the filter and add your own 317 * function tied to the excerpt_length filter hook. 318 */ 319 function twentyeleven_excerpt_length( $length ) { 320 return 40; 321 } 322 add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' ); 323 324 /** 325 * Returns a "Continue Reading" link for excerpts 326 */ 327 function twentyeleven_continue_reading_link() { 328 return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) . '</a>'; 329 } 330 331 /** 332 * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyeleven_continue_reading_link(). 333 * 334 * To override this in a child theme, remove the filter and add your own 335 * function tied to the excerpt_more filter hook. 336 */ 337 function twentyeleven_auto_excerpt_more( $more ) { 338 return ' …' . twentyeleven_continue_reading_link(); 339 } 340 add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' ); 341 342 /** 343 * Adds a pretty "Continue Reading" link to custom post excerpts. 344 * 345 * To override this link in a child theme, remove the filter and add your own 346 * function tied to the get_the_excerpt filter hook. 347 */ 348 function twentyeleven_custom_excerpt_more( $output ) { 349 if ( has_excerpt() && ! is_attachment() ) { 350 $output .= twentyeleven_continue_reading_link(); 351 } 352 return $output; 353 } 354 add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' ); 355 356 /** 357 * Add custom body classes 358 */ 359 function twentyeleven_singular_class( $classes ) { 360 if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) ) 361 $classes[] = 'singular'; 362 363 return $classes; 364 } 365 add_filter( 'body_class', 'twentyeleven_singular_class' ); 366 367 /** 368 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link. 369 */ 370 function twentyeleven_page_menu_args( $args ) { 371 $args['show_home'] = true; 372 return $args; 373 } 374 add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' ); 375 376 /** 377 * Register our sidebars and widgetized areas. Also register the default Epherma widget. 378 * 379 * @since Twenty Eleven 1.0 380 */ 381 function twentyeleven_widgets_init() { 382 383 register_widget( 'Twenty_Eleven_Ephemera_Widget' ); 384 385 register_sidebar( array( 386 'name' => __( 'Main Sidebar', 'twentyeleven' ), 387 'id' => 'sidebar-1', 388 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 389 'after_widget' => "</aside>", 390 'before_title' => '<h1 class="widget-title">', 391 'after_title' => '</h1>', 392 ) ); 393 394 register_sidebar( array( 395 'name' => __( 'Showcase Sidebar', 'twentyeleven' ), 396 'id' => 'sidebar-2', 397 'description' => __( 'The sidebar for the optional Showcase Template', 'twentyeleven' ), 398 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 399 'after_widget' => "</aside>", 400 'before_title' => '<h1 class="widget-title">', 401 'after_title' => '</h1>', 402 ) ); 403 404 register_sidebar( array( 405 'name' => __( 'Footer Area One', 'twentyeleven' ), 406 'id' => 'sidebar-3', 407 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), 408 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 409 'after_widget' => "</aside>", 410 'before_title' => '<h1 class="widget-title">', 411 'after_title' => '</h1>', 412 ) ); 413 414 register_sidebar( array( 415 'name' => __( 'Footer Area Two', 'twentyeleven' ), 416 'id' => 'sidebar-4', 417 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), 418 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 419 'after_widget' => "</aside>", 420 'before_title' => '<h1 class="widget-title">', 421 'after_title' => '</h1>', 422 ) ); 423 424 register_sidebar( array( 425 'name' => __( 'Footer Area Three', 'twentyeleven' ), 426 'id' => 'sidebar-5', 427 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), 428 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 429 'after_widget' => "</aside>", 430 'before_title' => '<h1 class="widget-title">', 431 'after_title' => '</h1>', 432 ) ); 433 } 434 add_action( 'widgets_init', 'twentyeleven_widgets_init' ); 435 436 /** 437 * Display navigation to next/previous pages when applicable 438 */ 439 function twentyeleven_content_nav( $nav_id ) { 440 global $wp_query; 441 442 if ( $wp_query->max_num_pages > 1 ) : ?> 443 <nav id="<?php echo $nav_id; ?>"> 444 <h1 class="section-heading"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h1> 445 <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyeleven' ) ); ?></div> 446 <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></div> 447 </nav><!-- #nav-above --> 448 <?php endif; 449 } 450 451 /** 452 * Return the URL for the first link found in the post content. 453 * 454 * @since Twenty Eleven 1.0 455 * @return string|bool URL or false when no link is present. 456 */ 457 function twentyeleven_url_grabber() { 458 if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) ) 459 return false; 460 461 return esc_url_raw( $matches[1] ); 462 } 463 464 /** 465 * Count the number of footer sidebars to enable dynamic classes for the footer 466 */ 467 function twentyeleven_footer_sidebar_class() { 468 $count = 0; 469 470 if ( is_active_sidebar( 'sidebar-3' ) ) 471 $count++; 472 473 if ( is_active_sidebar( 'sidebar-4' ) ) 474 $count++; 475 476 if ( is_active_sidebar( 'sidebar-5' ) ) 477 $count++; 478 479 $class = ''; 480 481 switch ( $count ) { 482 case '1': 483 $class = 'one'; 484 break; 485 case '2': 486 $class = 'two'; 487 break; 488 case '3': 489 $class = 'three'; 490 break; 491 } 492 493 if ( $class ) 494 echo 'class="' . $class . '"'; 495 } 496 497 if ( ! function_exists( 'twentyeleven_comment' ) ) : 498 /** 499 * Template for comments and pingbacks. 500 * 501 * To override this walker in a child theme without modifying the comments template 502 * simply create your own twentyeleven_comment(), and that function will be used instead. 503 * 504 * Used as a callback by wp_list_comments() for displaying the comments. 505 * 506 * @since Twenty Eleven 1.0 507 */ 508 function twentyeleven_comment( $comment, $args, $depth ) { 509 $GLOBALS['comment'] = $comment; 510 switch ( $comment->comment_type ) : 511 case 'pingback' : 512 case 'trackback' : 513 ?> 514 <li class="post pingback"> 515 <p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyeleven' ), ' ' ); ?></p> 516 <?php 517 break; 518 default : 519 ?> 520 <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"> 521 <article id="comment-<?php comment_ID(); ?>" class="comment"> 522 <footer class="comment-meta"> 523 <div class="comment-author vcard"> 524 <?php 525 $avatar_size = 68; 526 if ( '0' != $comment->comment_parent ) 527 $avatar_size = 39; 528 529 echo get_avatar( $comment, $avatar_size ); 530 531 printf( __( '%1$s on %2$s%3$s at %4$s%5$s <span class="says">said:</span>', 'twentyeleven' ), 532 sprintf( '<span class="fn">%s</span>', get_comment_author_link() ), 533 '<a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '"><time pubdate datetime="' . get_comment_time( 'c' ) . '">', 534 get_comment_date(), 535 get_comment_time(), 536 '</time></a>' 537 ); 538 ?> 539 540 <?php edit_comment_link( __( '[Edit]', 'twentyeleven' ), ' ' ); ?> 541 </div><!-- .comment-author .vcard --> 542 543 <?php if ( $comment->comment_approved == '0' ) : ?> 544 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyeleven' ); ?></em> 545 <br /> 546 <?php endif; ?> 547 548 </footer> 549 550 <div class="comment-content"><?php comment_text(); ?></div> 551 552 <div class="reply"> 553 <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply ↓', 'twentyeleven' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> 554 </div><!-- .reply --> 555 </article><!-- #comment-## --> 556 557 <?php 558 break; 559 endswitch; 560 } 561 endif; // ends check for twentyeleven_comment()
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jun 1 08:30:02 2011 |
Cross-referenced by PHPXref 0.7 Provided by Yoast and awesome WordPress Hosting |