| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[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 you can override certain functions (those wrapped 13 * in a function_exists() call) by defining them first in your child theme's 14 * functions.php file. The child theme's functions.php file is included before 15 * the parent theme's file, so the child theme functions would be used. 16 * 17 * @link https://developer.wordpress.org/themes/basics/theme-functions/ 18 * @link https://developer.wordpress.org/themes/advanced-topics/child-themes/ 19 * 20 * Functions that are not pluggable (not wrapped in function_exists()) are instead attached 21 * to a filter or action hook. The hook can be removed by using remove_action() or 22 * remove_filter() and you can attach your own function to the hook. 23 * 24 * We can remove the parent theme's hook only after it is attached, which means we need to 25 * wait until setting up the child theme: 26 * 27 * <code> 28 * add_action( 'after_setup_theme', 'my_child_theme_setup' ); 29 * function my_child_theme_setup() { 30 * // We are providing our own filter for excerpt_length (or using the unfiltered value). 31 * remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' ); 32 * ... 33 * } 34 * </code> 35 * 36 * For more information on hooks, actions, and filters, see https://developer.wordpress.org/plugins/. 37 * 38 * @package WordPress 39 * @subpackage Twenty_Eleven 40 * @since Twenty Eleven 1.0 41 */ 42 43 // Set the content width based on the theme's design and stylesheet. 44 if ( ! isset( $content_width ) ) { 45 $content_width = 584; 46 } 47 48 /* 49 * Tell WordPress to run twentyeleven_setup() when the 'after_setup_theme' hook is run. 50 */ 51 add_action( 'after_setup_theme', 'twentyeleven_setup' ); 52 53 if ( ! function_exists( 'twentyeleven_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 twentyeleven_setup() in a child theme, add your own twentyeleven_setup to your child theme's 62 * functions.php file. 63 * 64 * @uses load_theme_textdomain() For translation/localization support. 65 * @uses add_editor_style() To style the visual editor. 66 * @uses add_theme_support() To add support for post thumbnails, automatic feed links, custom headers 67 * and backgrounds, and post formats. 68 * @uses register_nav_menus() To add support for navigation menus. 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 /* 77 * Make Twenty Eleven available for translation. 78 * Translations can be added to the /languages/ directory. 79 * If you're building a theme based on Twenty Eleven, use 80 * a find and replace to change 'twentyeleven' to the name 81 * of your theme in all the template files. 82 * 83 * Manual loading of text domain is not required after the introduction of 84 * just in time translation loading in WordPress version 4.6. 85 * 86 * @ticket 58318 87 */ 88 if ( version_compare( $GLOBALS['wp_version'], '4.6', '<' ) ) { 89 load_theme_textdomain( 'twentyeleven', get_template_directory() . '/languages' ); 90 } 91 92 // This theme styles the visual editor with editor-style.css to match the theme style. 93 add_editor_style(); 94 95 // Load regular editor styles into the new block-based editor. 96 add_theme_support( 'editor-styles' ); 97 98 // Load default block styles. 99 add_theme_support( 'wp-block-styles' ); 100 101 // Add support for responsive embeds. 102 add_theme_support( 'responsive-embeds' ); 103 104 // Add support for custom color scheme. 105 add_theme_support( 106 'editor-color-palette', 107 array( 108 array( 109 'name' => __( 'Blue', 'twentyeleven' ), 110 'slug' => 'blue', 111 'color' => '#1982d1', 112 ), 113 array( 114 'name' => __( 'Black', 'twentyeleven' ), 115 'slug' => 'black', 116 'color' => '#000', 117 ), 118 array( 119 'name' => __( 'Dark Gray', 'twentyeleven' ), 120 'slug' => 'dark-gray', 121 'color' => '#373737', 122 ), 123 array( 124 'name' => __( 'Medium Gray', 'twentyeleven' ), 125 'slug' => 'medium-gray', 126 'color' => '#666', 127 ), 128 array( 129 'name' => __( 'Light Gray', 'twentyeleven' ), 130 'slug' => 'light-gray', 131 'color' => '#e2e2e2', 132 ), 133 array( 134 'name' => __( 'White', 'twentyeleven' ), 135 'slug' => 'white', 136 'color' => '#fff', 137 ), 138 ) 139 ); 140 141 // Load up our theme options page and related code. 142 require get_template_directory() . '/inc/theme-options.php'; 143 144 // Grab Twenty Eleven's Ephemera widget. 145 require get_template_directory() . '/inc/widgets.php'; 146 147 // Load block patterns. 148 require get_template_directory() . '/inc/block-patterns.php'; 149 150 // Add default posts and comments RSS feed links to <head>. 151 add_theme_support( 'automatic-feed-links' ); 152 153 // This theme uses wp_nav_menu() in one location. 154 register_nav_menu( 'primary', __( 'Primary Menu', 'twentyeleven' ) ); 155 156 // Add support for a variety of post formats. 157 add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) ); 158 159 $theme_options = twentyeleven_get_theme_options(); 160 if ( 'dark' === $theme_options['color_scheme'] ) { 161 $default_background_color = '1d1d1d'; 162 } else { 163 $default_background_color = 'e2e2e2'; 164 } 165 166 // Add support for custom backgrounds. 167 add_theme_support( 168 'custom-background', 169 array( 170 /* 171 * Let WordPress know what our default background color is. 172 * This is dependent on our current color scheme. 173 */ 174 'default-color' => $default_background_color, 175 ) 176 ); 177 178 // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images. 179 add_theme_support( 'post-thumbnails' ); 180 181 // Add support for custom headers. 182 $custom_header_support = array( 183 // The default header text color. 184 'default-text-color' => '000', 185 // The height and width of our custom header. 186 /** 187 * Filters the Twenty Eleven default header image width. 188 * 189 * @since Twenty Eleven 1.0 190 * 191 * @param int $width The default header image width in pixels. Default 1000. 192 */ 193 'width' => apply_filters( 'twentyeleven_header_image_width', 1000 ), 194 /** 195 * Filters the Twenty Eleven default header image height. 196 * 197 * @since Twenty Eleven 1.0 198 * 199 * @param int $height The default header image height in pixels. Default 288. 200 */ 201 'height' => apply_filters( 'twentyeleven_header_image_height', 288 ), 202 // Support flexible heights. 203 'flex-height' => true, 204 // Random image rotation by default. 205 'random-default' => true, 206 // Callback for styling the header. 207 'wp-head-callback' => 'twentyeleven_header_style', 208 // Callback for styling the header preview in the admin. 209 'admin-head-callback' => 'twentyeleven_admin_header_style', 210 // Callback used to display the header preview in the admin. 211 'admin-preview-callback' => 'twentyeleven_admin_header_image', 212 ); 213 214 add_theme_support( 'custom-header', $custom_header_support ); 215 216 if ( ! function_exists( 'get_custom_header' ) ) { 217 // This is all for compatibility with versions of WordPress prior to 3.4. 218 define( 'HEADER_TEXTCOLOR', $custom_header_support['default-text-color'] ); 219 define( 'HEADER_IMAGE', '' ); 220 define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] ); 221 define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] ); 222 add_custom_image_header( $custom_header_support['wp-head-callback'], $custom_header_support['admin-head-callback'], $custom_header_support['admin-preview-callback'] ); 223 add_custom_background(); 224 } 225 226 /* 227 * We'll be using post thumbnails for custom header images on posts and pages. 228 * We want them to be the size of the header image that we just defined. 229 * Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php. 230 */ 231 set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true ); 232 233 /* 234 * Add Twenty Eleven's custom image sizes. 235 * Used for large feature (header) images. 236 */ 237 add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true ); 238 // Used for featured posts if a large-feature doesn't exist. 239 add_image_size( 'small-feature', 500, 300 ); 240 241 // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. 242 register_default_headers( 243 array( 244 'wheel' => array( 245 'url' => '%s/images/headers/wheel.jpg', 246 'thumbnail_url' => '%s/images/headers/wheel-thumbnail.jpg', 247 /* translators: Header image description. */ 248 'description' => __( 'Wheel', 'twentyeleven' ), 249 ), 250 'shore' => array( 251 'url' => '%s/images/headers/shore.jpg', 252 'thumbnail_url' => '%s/images/headers/shore-thumbnail.jpg', 253 /* translators: Header image description. */ 254 'description' => __( 'Shore', 'twentyeleven' ), 255 ), 256 'trolley' => array( 257 'url' => '%s/images/headers/trolley.jpg', 258 'thumbnail_url' => '%s/images/headers/trolley-thumbnail.jpg', 259 /* translators: Header image description. */ 260 'description' => __( 'Trolley', 'twentyeleven' ), 261 ), 262 'pine-cone' => array( 263 'url' => '%s/images/headers/pine-cone.jpg', 264 'thumbnail_url' => '%s/images/headers/pine-cone-thumbnail.jpg', 265 /* translators: Header image description. */ 266 'description' => __( 'Pine Cone', 'twentyeleven' ), 267 ), 268 'chessboard' => array( 269 'url' => '%s/images/headers/chessboard.jpg', 270 'thumbnail_url' => '%s/images/headers/chessboard-thumbnail.jpg', 271 /* translators: Header image description. */ 272 'description' => __( 'Chessboard', 'twentyeleven' ), 273 ), 274 'lanterns' => array( 275 'url' => '%s/images/headers/lanterns.jpg', 276 'thumbnail_url' => '%s/images/headers/lanterns-thumbnail.jpg', 277 /* translators: Header image description. */ 278 'description' => __( 'Lanterns', 'twentyeleven' ), 279 ), 280 'willow' => array( 281 'url' => '%s/images/headers/willow.jpg', 282 'thumbnail_url' => '%s/images/headers/willow-thumbnail.jpg', 283 /* translators: Header image description. */ 284 'description' => __( 'Willow', 'twentyeleven' ), 285 ), 286 'hanoi' => array( 287 'url' => '%s/images/headers/hanoi.jpg', 288 'thumbnail_url' => '%s/images/headers/hanoi-thumbnail.jpg', 289 /* translators: Header image description. */ 290 'description' => __( 'Hanoi Plant', 'twentyeleven' ), 291 ), 292 ) 293 ); 294 295 // Indicate widget sidebars can use selective refresh in the Customizer. 296 add_theme_support( 'customize-selective-refresh-widgets' ); 297 } 298 endif; // twentyeleven_setup() 299 300 /** 301 * Enqueues scripts and styles for front end. 302 * 303 * @since Twenty Eleven 2.9 304 */ 305 function twentyeleven_scripts_styles() { 306 // Theme block stylesheet. 307 wp_enqueue_style( 'twentyeleven-block-style', get_template_directory_uri() . '/blocks.css', array(), '20240703' ); 308 } 309 add_action( 'wp_enqueue_scripts', 'twentyeleven_scripts_styles' ); 310 311 /** 312 * Enqueues styles for the block-based editor. 313 * 314 * @since Twenty Eleven 2.9 315 */ 316 function twentyeleven_block_editor_styles() { 317 // Block styles. 318 wp_enqueue_style( 'twentyeleven-block-editor-style', get_template_directory_uri() . '/editor-blocks.css', array(), '20240716' ); 319 } 320 add_action( 'enqueue_block_editor_assets', 'twentyeleven_block_editor_styles' ); 321 322 if ( ! function_exists( 'twentyeleven_header_style' ) ) : 323 /** 324 * Styles the header image and text displayed on the blog. 325 * 326 * @since Twenty Eleven 1.0 327 */ 328 function twentyeleven_header_style() { 329 $text_color = get_header_textcolor(); 330 331 // If no custom options for text are set, let's bail. 332 if ( HEADER_TEXTCOLOR === $text_color ) { 333 return; 334 } 335 336 // If we get this far, we have custom styles. Let's do this. 337 ?> 338 <style id="twentyeleven-header-css"> 339 <?php 340 // Has the text been hidden? 341 if ( 'blank' === $text_color ) : 342 ?> 343 #site-title, 344 #site-description { 345 position: absolute; 346 clip-path: inset(50%); 347 } 348 <?php 349 // If the user has set a custom color for the text, use that. 350 else : 351 ?> 352 #site-title a, 353 #site-description { 354 color: #<?php echo $text_color; ?>; 355 } 356 <?php endif; ?> 357 </style> 358 <?php 359 } 360 endif; // twentyeleven_header_style() 361 362 if ( ! function_exists( 'twentyeleven_admin_header_style' ) ) : 363 /** 364 * Styles the header image displayed on the Appearance > Header admin panel. 365 * 366 * Referenced via add_theme_support('custom-header') in twentyeleven_setup(). 367 * 368 * @since Twenty Eleven 1.0 369 */ 370 function twentyeleven_admin_header_style() { 371 ?> 372 <style id="twentyeleven-admin-header-css"> 373 .appearance_page_custom-header #headimg { 374 border: none; 375 } 376 #headimg h1, 377 #desc { 378 font-family: "Helvetica Neue", Arial, Helvetica, "Nimbus Sans L", sans-serif; 379 } 380 #headimg h1 { 381 margin: 0; 382 } 383 #headimg h1 a { 384 font-size: 32px; 385 line-height: 36px; 386 text-decoration: none; 387 } 388 #desc { 389 font-size: 14px; 390 line-height: 23px; 391 padding: 0 0 3em; 392 } 393 <?php 394 // If the user has set a custom color for the text, use that. 395 if ( get_header_textcolor() !== HEADER_TEXTCOLOR ) : 396 ?> 397 #site-title a, 398 #site-description { 399 color: #<?php echo get_header_textcolor(); ?>; 400 } 401 <?php endif; ?> 402 #headimg img { 403 max-width: 1000px; 404 height: auto; 405 width: 100%; 406 } 407 </style> 408 <?php 409 } 410 endif; // twentyeleven_admin_header_style() 411 412 if ( ! function_exists( 'twentyeleven_admin_header_image' ) ) : 413 /** 414 * Displays custom header image markup on the Appearance > Header admin panel. 415 * 416 * Referenced via add_theme_support('custom-header') in twentyeleven_setup(). 417 * 418 * @since Twenty Eleven 1.0 419 */ 420 function twentyeleven_admin_header_image() { 421 422 ?> 423 <div id="headimg"> 424 <?php 425 $color = get_header_textcolor(); 426 $image = get_header_image(); 427 $style = 'display: none;'; 428 if ( $color && 'blank' !== $color ) { 429 $style = 'color: #' . $color . ';'; 430 } 431 ?> 432 <h1 class="displaying-header-text"><a id="name" style="<?php echo esc_attr( $style ); ?>" onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>" tabindex="-1"><?php bloginfo( 'name' ); ?></a></h1> 433 <div id="desc" class="displaying-header-text" style="<?php echo esc_attr( $style ); ?>"><?php bloginfo( 'description' ); ?></div> 434 <?php if ( $image ) : ?> 435 <img src="<?php echo esc_url( $image ); ?>" alt="" /> 436 <?php endif; ?> 437 </div> 438 <?php 439 } 440 endif; // twentyeleven_admin_header_image() 441 442 443 if ( ! function_exists( 'twentyeleven_header_image' ) ) : 444 /** 445 * Displays custom header image markup. 446 * 447 * @since Twenty Eleven 4.5 448 */ 449 function twentyeleven_header_image() { 450 $attrs = array( 451 'alt' => get_bloginfo( 'name', 'display' ), 452 ); 453 454 // Compatibility with versions of WordPress prior to 3.4. 455 if ( function_exists( 'get_custom_header' ) ) { 456 $custom_header = get_custom_header(); 457 $attrs['width'] = $custom_header->width; 458 $attrs['height'] = $custom_header->height; 459 } else { 460 $attrs['width'] = HEADER_IMAGE_WIDTH; 461 $attrs['height'] = HEADER_IMAGE_HEIGHT; 462 } 463 464 if ( function_exists( 'the_header_image_tag' ) ) { 465 the_header_image_tag( $attrs ); 466 return; 467 } 468 469 ?> 470 <img src="<?php header_image(); ?>" width="<?php echo esc_attr( $attrs['width'] ); ?>" height="<?php echo esc_attr( $attrs['height'] ); ?>" alt="<?php echo esc_attr( $attrs['alt'] ); ?>" /> 471 <?php 472 } 473 endif; // twentyeleven_header_image() 474 475 /** 476 * Sets the post excerpt length to 40 words. 477 * 478 * To override this length in a child theme, remove 479 * the filter and add your own function tied to 480 * the excerpt_length filter hook. 481 * 482 * @since Twenty Eleven 1.0 483 * 484 * @param int $length The number of excerpt characters. 485 * @return int The filtered number of characters. 486 */ 487 function twentyeleven_excerpt_length( $length ) { 488 return 40; 489 } 490 add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' ); 491 492 if ( ! function_exists( 'twentyeleven_continue_reading_link' ) ) : 493 /** 494 * Returns a "Continue Reading" link for excerpts. 495 * 496 * @since Twenty Eleven 1.0 497 * 498 * @return string The "Continue Reading" HTML link. 499 */ 500 function twentyeleven_continue_reading_link() { 501 return ' <a href="' . esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) . '</a>'; 502 } 503 endif; // twentyeleven_continue_reading_link() 504 505 /** 506 * Replaces "[...]" in the Read More link with an ellipsis. 507 * 508 * The "[...]" is appended to automatically generated excerpts. 509 * 510 * To override this in a child theme, remove the filter and add your own 511 * function tied to the excerpt_more filter hook. 512 * 513 * @since Twenty Eleven 1.0 514 * 515 * @param string $more The Read More text. 516 * @return string The filtered Read More text. 517 */ 518 function twentyeleven_auto_excerpt_more( $more ) { 519 if ( ! is_admin() ) { 520 return ' …' . twentyeleven_continue_reading_link(); 521 } 522 return $more; 523 } 524 add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' ); 525 526 /** 527 * Adds a pretty "Continue Reading" link to custom post excerpts. 528 * 529 * To override this link in a child theme, remove the filter and add your own 530 * function tied to the get_the_excerpt filter hook. 531 * 532 * @since Twenty Eleven 1.0 533 * 534 * @param string $output The "Continue Reading" link. 535 * @return string The filtered "Continue Reading" link. 536 */ 537 function twentyeleven_custom_excerpt_more( $output ) { 538 if ( has_excerpt() && ! is_attachment() && ! is_admin() ) { 539 $output .= twentyeleven_continue_reading_link(); 540 } 541 return $output; 542 } 543 add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' ); 544 545 /** 546 * Shows a home link for the wp_nav_menu() fallback, wp_page_menu(). 547 * 548 * @since Twenty Eleven 1.0 549 * 550 * @param array $args The page menu arguments. @see wp_page_menu() 551 * @return array The filtered page menu arguments. 552 */ 553 function twentyeleven_page_menu_args( $args ) { 554 if ( ! isset( $args['show_home'] ) ) { 555 $args['show_home'] = true; 556 } 557 return $args; 558 } 559 add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' ); 560 561 /** 562 * Registers sidebars and widgetized areas. 563 * 564 * Also register the default Ephemera widget. 565 * 566 * @since Twenty Eleven 1.0 567 */ 568 function twentyeleven_widgets_init() { 569 570 register_widget( 'Twenty_Eleven_Ephemera_Widget' ); 571 572 register_sidebar( 573 array( 574 'name' => __( 'Main Sidebar', 'twentyeleven' ), 575 'id' => 'sidebar-1', 576 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 577 'after_widget' => '</aside>', 578 'before_title' => '<h3 class="widget-title">', 579 'after_title' => '</h3>', 580 ) 581 ); 582 583 register_sidebar( 584 array( 585 'name' => __( 'Showcase Sidebar', 'twentyeleven' ), 586 'id' => 'sidebar-2', 587 'description' => __( 'The sidebar for the optional Showcase Template', 'twentyeleven' ), 588 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 589 'after_widget' => '</aside>', 590 'before_title' => '<h3 class="widget-title">', 591 'after_title' => '</h3>', 592 ) 593 ); 594 595 register_sidebar( 596 array( 597 'name' => __( 'Footer Area One', 'twentyeleven' ), 598 'id' => 'sidebar-3', 599 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), 600 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 601 'after_widget' => '</aside>', 602 'before_title' => '<h3 class="widget-title">', 603 'after_title' => '</h3>', 604 ) 605 ); 606 607 register_sidebar( 608 array( 609 'name' => __( 'Footer Area Two', 'twentyeleven' ), 610 'id' => 'sidebar-4', 611 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), 612 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 613 'after_widget' => '</aside>', 614 'before_title' => '<h3 class="widget-title">', 615 'after_title' => '</h3>', 616 ) 617 ); 618 619 register_sidebar( 620 array( 621 'name' => __( 'Footer Area Three', 'twentyeleven' ), 622 'id' => 'sidebar-5', 623 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), 624 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 625 'after_widget' => '</aside>', 626 'before_title' => '<h3 class="widget-title">', 627 'after_title' => '</h3>', 628 ) 629 ); 630 } 631 add_action( 'widgets_init', 'twentyeleven_widgets_init' ); 632 633 if ( ! function_exists( 'twentyeleven_content_nav' ) ) : 634 /** 635 * Displays navigation to next/previous pages when applicable. 636 * 637 * @since Twenty Eleven 1.0 638 * 639 * @param string $html_id The HTML id attribute. 640 */ 641 function twentyeleven_content_nav( $html_id ) { 642 global $wp_query; 643 644 if ( $wp_query->max_num_pages > 1 ) : 645 $order = get_query_var( 'order', 'DESC' ); 646 $is_desc = ( 'DESC' === $order ); 647 648 $new_posts_text = __( 'Newer posts <span class="meta-nav">→</span>', 'twentyeleven' ); 649 $old_posts_text = __( '<span class="meta-nav">←</span> Older posts', 'twentyeleven' ); 650 651 $prev_link = $is_desc ? get_next_posts_link( $old_posts_text ) : get_previous_posts_link( $old_posts_text ); 652 $next_link = $is_desc ? get_previous_posts_link( $new_posts_text ) : get_next_posts_link( $new_posts_text ); 653 ?> 654 <nav id="<?php echo esc_attr( $html_id ); ?>"> 655 <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3> 656 <?php if ( $prev_link ) : ?> 657 <div class="nav-previous"><?php echo $prev_link; ?></div> 658 <?php endif; ?> 659 660 <?php if ( $next_link ) : ?> 661 <div class="nav-next"><?php echo $next_link; ?></div> 662 <?php endif; ?> 663 </nav><!-- #<?php echo esc_attr( $html_id ); ?> --> 664 <?php 665 endif; 666 } 667 endif; // twentyeleven_content_nav() 668 669 /** 670 * Returns the first link from the post content. If none found, the 671 * post permalink is used as a fallback. 672 * 673 * @since Twenty Eleven 1.0 674 * 675 * @uses get_url_in_content() to get the first URL from the post content. 676 * 677 * @return string The first link. 678 */ 679 function twentyeleven_get_first_url() { 680 $content = get_the_content(); 681 $has_url = function_exists( 'get_url_in_content' ) ? get_url_in_content( $content ) : false; 682 683 if ( ! $has_url ) { 684 $has_url = twentyeleven_url_grabber(); 685 } 686 687 /** This filter is documented in wp-includes/link-template.php */ 688 return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() ); 689 } 690 691 /** 692 * Returns the URL for the first link found in the post content. 693 * 694 * @since Twenty Eleven 1.0 695 * 696 * @return string|bool URL or false when no link is present. 697 */ 698 function twentyeleven_url_grabber() { 699 if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) ) { 700 return false; 701 } 702 703 return esc_url_raw( $matches[1] ); 704 } 705 706 /** 707 * Counts the number of footer sidebars to enable dynamic classes for the footer. 708 * 709 * @since Twenty Eleven 1.0 710 */ 711 function twentyeleven_footer_sidebar_class() { 712 $count = 0; 713 714 if ( is_active_sidebar( 'sidebar-3' ) ) { 715 ++$count; 716 } 717 718 if ( is_active_sidebar( 'sidebar-4' ) ) { 719 ++$count; 720 } 721 722 if ( is_active_sidebar( 'sidebar-5' ) ) { 723 ++$count; 724 } 725 726 $class = ''; 727 728 switch ( $count ) { 729 case '1': 730 $class = 'one'; 731 break; 732 case '2': 733 $class = 'two'; 734 break; 735 case '3': 736 $class = 'three'; 737 break; 738 } 739 740 if ( $class ) { 741 echo 'class="' . esc_attr( $class ) . '"'; 742 } 743 } 744 745 if ( ! function_exists( 'twentyeleven_comment' ) ) : 746 /** 747 * Template for comments and pingbacks. 748 * 749 * To override this walker in a child theme without modifying the comments template 750 * simply create your own twentyeleven_comment(), and that function will be used instead. 751 * 752 * Used as a callback by wp_list_comments() for displaying the comments. 753 * 754 * @since Twenty Eleven 1.0 755 * 756 * @param WP_Comment $comment The comment object. 757 * @param array $args An array of comment arguments. @see get_comment_reply_link() 758 * @param int $depth The depth of the comment. 759 */ 760 function twentyeleven_comment( $comment, $args, $depth ) { 761 $GLOBALS['comment'] = $comment; 762 switch ( $comment->comment_type ) : 763 case 'pingback': 764 case 'trackback': 765 ?> 766 <li class="post pingback"> 767 <p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p> 768 <?php 769 break; 770 default: 771 ?> 772 <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"> 773 <article id="comment-<?php comment_ID(); ?>" class="comment"> 774 <footer class="comment-meta"> 775 <div class="comment-author vcard"> 776 <?php 777 $avatar_size = 68; 778 779 if ( '0' !== $comment->comment_parent ) { 780 $avatar_size = 39; 781 } 782 783 echo get_avatar( $comment, $avatar_size ); 784 785 printf( 786 /* translators: 1: Comment author, 2: Date and time. */ 787 __( '%1$s on %2$s <span class="says">said:</span>', 'twentyeleven' ), 788 sprintf( '<span class="fn">%s</span>', get_comment_author_link() ), 789 sprintf( 790 '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>', 791 esc_url( get_comment_link( $comment->comment_ID ) ), 792 get_comment_time( 'c' ), 793 /* translators: 1: Date, 2: Time. */ 794 sprintf( __( '%1$s at %2$s', 'twentyeleven' ), get_comment_date(), get_comment_time() ) 795 ) 796 ); 797 ?> 798 799 <?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?> 800 </div><!-- .comment-author .vcard --> 801 802 <?php 803 $commenter = wp_get_current_commenter(); 804 if ( $commenter['comment_author_email'] ) { 805 $moderation_note = __( 'Your comment is awaiting moderation.', 'twentyeleven' ); 806 } else { 807 $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.', 'twentyeleven' ); 808 } 809 ?> 810 811 <?php if ( '0' === $comment->comment_approved ) : ?> 812 <em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em> 813 <br /> 814 <?php endif; ?> 815 816 </footer> 817 818 <div class="comment-content"><?php comment_text(); ?></div> 819 820 <div class="reply"> 821 <?php 822 comment_reply_link( 823 array_merge( 824 $args, 825 array( 826 'reply_text' => __( 'Reply <span>↓</span>', 'twentyeleven' ), 827 'depth' => $depth, 828 'max_depth' => $args['max_depth'], 829 ) 830 ) 831 ); 832 ?> 833 </div><!-- .reply --> 834 </article><!-- #comment-## --> 835 836 <?php 837 break; 838 endswitch; 839 } 840 endif; // twentyeleven_comment() 841 842 if ( ! function_exists( 'twentyeleven_posted_on' ) ) : 843 /** 844 * Prints HTML with meta information for the current post-date/time and author. 845 * 846 * Create your own twentyeleven_posted_on to override in a child theme 847 * 848 * @since Twenty Eleven 1.0 849 */ 850 function twentyeleven_posted_on() { 851 printf( 852 /* translators: 1: The permalink, 2: Time, 3: Date and time, 4: Date and time, 5: Author posts, 6: Author post link text, 7: Author display name. */ 853 __( '<span class="sep">Posted on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven' ), 854 esc_url( get_permalink() ), 855 esc_attr( get_the_time() ), 856 esc_attr( get_the_date( 'c' ) ), 857 esc_html( get_the_date() ), 858 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), 859 /* translators: %s: Author display name. */ 860 esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ), 861 get_the_author() 862 ); 863 } 864 endif; 865 866 /** 867 * Adds two classes to the array of body classes. 868 * 869 * The first is if the site has only had one author with published posts. 870 * The second is if a singular post being displayed 871 * 872 * @since Twenty Eleven 1.0 873 * 874 * @param array $classes Existing body classes. 875 * @return array The filtered array of body classes. 876 */ 877 function twentyeleven_body_classes( $classes ) { 878 879 if ( function_exists( 'is_multi_author' ) && ! is_multi_author() ) { 880 $classes[] = 'single-author'; 881 } 882 883 if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) ) { 884 $classes[] = 'singular'; 885 } 886 887 return $classes; 888 } 889 add_filter( 'body_class', 'twentyeleven_body_classes' ); 890 891 /** 892 * Retrieves the IDs for images in a gallery. 893 * 894 * @uses get_post_galleries() First, if available. Falls back to shortcode parsing, 895 * then as last option uses a get_posts() call. 896 * 897 * @since Twenty Eleven 1.6 898 * 899 * @return array List of image IDs from the post gallery. 900 */ 901 function twentyeleven_get_gallery_images() { 902 $images = array(); 903 904 if ( function_exists( 'get_post_galleries' ) ) { 905 $galleries = get_post_galleries( get_the_ID(), false ); 906 if ( isset( $galleries[0]['ids'] ) ) { 907 $images = explode( ',', $galleries[0]['ids'] ); 908 } 909 } else { 910 $pattern = get_shortcode_regex(); 911 preg_match( "/$pattern/s", get_the_content(), $match ); 912 $atts = shortcode_parse_atts( $match[3] ); 913 if ( isset( $atts['ids'] ) ) { 914 $images = explode( ',', $atts['ids'] ); 915 } 916 } 917 918 if ( ! $images ) { 919 $images = get_posts( 920 array( 921 'fields' => 'ids', 922 'numberposts' => 999, 923 'order' => 'ASC', 924 'orderby' => 'menu_order', 925 'post_mime_type' => 'image', 926 'post_parent' => get_the_ID(), 927 'post_type' => 'attachment', 928 ) 929 ); 930 } 931 932 return $images; 933 } 934 935 /** 936 * Modifies tag cloud widget arguments to display all tags in the same font size 937 * and use list format for better accessibility. 938 * 939 * @since Twenty Eleven 2.7 940 * 941 * @param array $args Arguments for tag cloud widget. 942 * @return array The filtered arguments for tag cloud widget. 943 */ 944 function twentyeleven_widget_tag_cloud_args( $args ) { 945 $args['largest'] = 22; 946 $args['smallest'] = 8; 947 $args['unit'] = 'pt'; 948 $args['format'] = 'list'; 949 950 return $args; 951 } 952 add_filter( 'widget_tag_cloud_args', 'twentyeleven_widget_tag_cloud_args' ); 953 954 if ( ! function_exists( 'wp_body_open' ) ) : 955 /** 956 * Fires the wp_body_open action. 957 * 958 * Added for backward compatibility to support pre-5.2.0 WordPress versions. 959 * 960 * @since Twenty Eleven 3.3 961 */ 962 function wp_body_open() { 963 /** 964 * Triggered after the opening <body> tag. 965 * 966 * @since Twenty Eleven 3.3 967 */ 968 do_action( 'wp_body_open' ); 969 } 970 endif; 971 972 /** 973 * Includes a skip to content link at the top of the page so that users can bypass the menu. 974 * 975 * @since Twenty Eleven 3.4 976 */ 977 function twentyeleven_skip_link() { 978 echo '<div class="skip-link"><a class="assistive-text" href="#content">' . esc_html__( 'Skip to primary content', 'twentyeleven' ) . '</a></div>'; 979 if ( ! is_singular() ) { 980 echo '<div class="skip-link"><a class="assistive-text" href="#secondary">' . esc_html__( 'Skip to secondary content', 'twentyeleven' ) . '</a></div>'; 981 } 982 } 983 add_action( 'wp_body_open', 'twentyeleven_skip_link', 5 ); 984 985 if ( ! function_exists( 'wp_get_list_item_separator' ) ) : 986 /** 987 * Retrieves the list item separator based on the locale. 988 * 989 * Added for backward compatibility to support pre-6.0.0 WordPress versions. 990 * 991 * @since Twenty Eleven 4.1 992 * 993 * @return string Locale-specific list item separator. 994 */ 995 function wp_get_list_item_separator() { 996 /* translators: Used between list items, there is a space after the comma. */ 997 return __( ', ', 'twentyeleven' ); 998 } 999 endif;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Thu Feb 26 08:20:04 2026 | Cross-referenced by PHPXref |