[ 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 * Set 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 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 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 * Enqueue 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 * Enqueue 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 type="text/css" 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: rect(1px 1px 1px 1px); /* IE6, IE7 */ 347 clip: rect(1px, 1px, 1px, 1px); 348 } 349 <?php 350 // If the user has set a custom color for the text, use that. 351 else : 352 ?> 353 #site-title a, 354 #site-description { 355 color: #<?php echo $text_color; ?>; 356 } 357 <?php endif; ?> 358 </style> 359 <?php 360 } 361 endif; // twentyeleven_header_style() 362 363 if ( ! function_exists( 'twentyeleven_admin_header_style' ) ) : 364 /** 365 * Styles the header image displayed on the Appearance > Header admin panel. 366 * 367 * Referenced via add_theme_support('custom-header') in twentyeleven_setup(). 368 * 369 * @since Twenty Eleven 1.0 370 */ 371 function twentyeleven_admin_header_style() { 372 ?> 373 <style type="text/css" id="twentyeleven-admin-header-css"> 374 .appearance_page_custom-header #headimg { 375 border: none; 376 } 377 #headimg h1, 378 #desc { 379 font-family: "Helvetica Neue", Arial, Helvetica, "Nimbus Sans L", sans-serif; 380 } 381 #headimg h1 { 382 margin: 0; 383 } 384 #headimg h1 a { 385 font-size: 32px; 386 line-height: 36px; 387 text-decoration: none; 388 } 389 #desc { 390 font-size: 14px; 391 line-height: 23px; 392 padding: 0 0 3em; 393 } 394 <?php 395 // If the user has set a custom color for the text, use that. 396 if ( get_header_textcolor() !== HEADER_TEXTCOLOR ) : 397 ?> 398 #site-title a, 399 #site-description { 400 color: #<?php echo get_header_textcolor(); ?>; 401 } 402 <?php endif; ?> 403 #headimg img { 404 max-width: 1000px; 405 height: auto; 406 width: 100%; 407 } 408 </style> 409 <?php 410 } 411 endif; // twentyeleven_admin_header_style() 412 413 if ( ! function_exists( 'twentyeleven_admin_header_image' ) ) : 414 /** 415 * Custom header image markup displayed on the Appearance > Header admin panel. 416 * 417 * Referenced via add_theme_support('custom-header') in twentyeleven_setup(). 418 * 419 * @since Twenty Eleven 1.0 420 */ 421 function twentyeleven_admin_header_image() { 422 423 ?> 424 <div id="headimg"> 425 <?php 426 $color = get_header_textcolor(); 427 $image = get_header_image(); 428 $style = 'display: none;'; 429 if ( $color && 'blank' !== $color ) { 430 $style = 'color: #' . $color . ';'; 431 } 432 ?> 433 <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> 434 <div id="desc" class="displaying-header-text" style="<?php echo esc_attr( $style ); ?>"><?php bloginfo( 'description' ); ?></div> 435 <?php if ( $image ) : ?> 436 <img src="<?php echo esc_url( $image ); ?>" alt="" /> 437 <?php endif; ?> 438 </div> 439 <?php 440 } 441 endif; // twentyeleven_admin_header_image() 442 443 444 if ( ! function_exists( 'twentyeleven_header_image' ) ) : 445 /** 446 * Custom header image markup displayed. 447 * 448 * @since Twenty Eleven 4.5 449 */ 450 function twentyeleven_header_image() { 451 $attrs = array( 452 'alt' => get_bloginfo( 'name', 'display' ), 453 ); 454 455 // Compatibility with versions of WordPress prior to 3.4. 456 if ( function_exists( 'get_custom_header' ) ) { 457 $custom_header = get_custom_header(); 458 $attrs['width'] = $custom_header->width; 459 $attrs['height'] = $custom_header->height; 460 } else { 461 $attrs['width'] = HEADER_IMAGE_WIDTH; 462 $attrs['height'] = HEADER_IMAGE_HEIGHT; 463 } 464 465 if ( function_exists( 'the_header_image_tag' ) ) { 466 the_header_image_tag( $attrs ); 467 return; 468 } 469 470 ?> 471 <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'] ); ?>" /> 472 <?php 473 } 474 endif; // twentyeleven_header_image() 475 476 /** 477 * Set the post excerpt length to 40 words. 478 * 479 * To override this length in a child theme, remove 480 * the filter and add your own function tied to 481 * the excerpt_length filter hook. 482 * 483 * @since Twenty Eleven 1.0 484 * 485 * @param int $length The number of excerpt characters. 486 * @return int The filtered number of characters. 487 */ 488 function twentyeleven_excerpt_length( $length ) { 489 return 40; 490 } 491 add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' ); 492 493 if ( ! function_exists( 'twentyeleven_continue_reading_link' ) ) : 494 /** 495 * Return a "Continue Reading" link for excerpts 496 * 497 * @since Twenty Eleven 1.0 498 * 499 * @return string The "Continue Reading" HTML link. 500 */ 501 function twentyeleven_continue_reading_link() { 502 return ' <a href="' . esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) . '</a>'; 503 } 504 endif; // twentyeleven_continue_reading_link() 505 506 /** 507 * Replace "[...]" in the Read More link with an ellipsis. 508 * 509 * The "[...]" is appended to automatically generated excerpts. 510 * 511 * To override this in a child theme, remove the filter and add your own 512 * function tied to the excerpt_more filter hook. 513 * 514 * @since Twenty Eleven 1.0 515 * 516 * @param string $more The Read More text. 517 * @return string The filtered Read More text. 518 */ 519 function twentyeleven_auto_excerpt_more( $more ) { 520 if ( ! is_admin() ) { 521 return ' …' . twentyeleven_continue_reading_link(); 522 } 523 return $more; 524 } 525 add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' ); 526 527 /** 528 * Add a pretty "Continue Reading" link to custom post excerpts. 529 * 530 * To override this link in a child theme, remove the filter and add your own 531 * function tied to the get_the_excerpt filter hook. 532 * 533 * @since Twenty Eleven 1.0 534 * 535 * @param string $output The "Continue Reading" link. 536 * @return string The filtered "Continue Reading" link. 537 */ 538 function twentyeleven_custom_excerpt_more( $output ) { 539 if ( has_excerpt() && ! is_attachment() && ! is_admin() ) { 540 $output .= twentyeleven_continue_reading_link(); 541 } 542 return $output; 543 } 544 add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' ); 545 546 /** 547 * Show a home link for the wp_nav_menu() fallback, wp_page_menu(). 548 * 549 * @since Twenty Eleven 1.0 550 * 551 * @param array $args The page menu arguments. @see wp_page_menu() 552 * @return array The filtered page menu arguments. 553 */ 554 function twentyeleven_page_menu_args( $args ) { 555 if ( ! isset( $args['show_home'] ) ) { 556 $args['show_home'] = true; 557 } 558 return $args; 559 } 560 add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' ); 561 562 /** 563 * Register sidebars and widgetized areas. 564 * 565 * Also register the default Ephemera widget. 566 * 567 * @since Twenty Eleven 1.0 568 */ 569 function twentyeleven_widgets_init() { 570 571 register_widget( 'Twenty_Eleven_Ephemera_Widget' ); 572 573 register_sidebar( 574 array( 575 'name' => __( 'Main Sidebar', 'twentyeleven' ), 576 'id' => 'sidebar-1', 577 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 578 'after_widget' => '</aside>', 579 'before_title' => '<h3 class="widget-title">', 580 'after_title' => '</h3>', 581 ) 582 ); 583 584 register_sidebar( 585 array( 586 'name' => __( 'Showcase Sidebar', 'twentyeleven' ), 587 'id' => 'sidebar-2', 588 'description' => __( 'The sidebar for the optional Showcase Template', 'twentyeleven' ), 589 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 590 'after_widget' => '</aside>', 591 'before_title' => '<h3 class="widget-title">', 592 'after_title' => '</h3>', 593 ) 594 ); 595 596 register_sidebar( 597 array( 598 'name' => __( 'Footer Area One', 'twentyeleven' ), 599 'id' => 'sidebar-3', 600 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), 601 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 602 'after_widget' => '</aside>', 603 'before_title' => '<h3 class="widget-title">', 604 'after_title' => '</h3>', 605 ) 606 ); 607 608 register_sidebar( 609 array( 610 'name' => __( 'Footer Area Two', 'twentyeleven' ), 611 'id' => 'sidebar-4', 612 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), 613 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 614 'after_widget' => '</aside>', 615 'before_title' => '<h3 class="widget-title">', 616 'after_title' => '</h3>', 617 ) 618 ); 619 620 register_sidebar( 621 array( 622 'name' => __( 'Footer Area Three', 'twentyeleven' ), 623 'id' => 'sidebar-5', 624 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), 625 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 626 'after_widget' => '</aside>', 627 'before_title' => '<h3 class="widget-title">', 628 'after_title' => '</h3>', 629 ) 630 ); 631 } 632 add_action( 'widgets_init', 'twentyeleven_widgets_init' ); 633 634 if ( ! function_exists( 'twentyeleven_content_nav' ) ) : 635 /** 636 * Display navigation to next/previous pages when applicable. 637 * 638 * @since Twenty Eleven 1.0 639 * 640 * @param string $html_id The HTML id attribute. 641 */ 642 function twentyeleven_content_nav( $html_id ) { 643 global $wp_query; 644 645 if ( $wp_query->max_num_pages > 1 ) : 646 ?> 647 <nav id="<?php echo esc_attr( $html_id ); ?>"> 648 <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3> 649 <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyeleven' ) ); ?></div> 650 <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></div> 651 </nav><!-- #nav-above --> 652 <?php 653 endif; 654 } 655 endif; // twentyeleven_content_nav() 656 657 /** 658 * Return the first link from the post content. If none found, the 659 * post permalink is used as a fallback. 660 * 661 * @since Twenty Eleven 1.0 662 * 663 * @uses get_url_in_content() to get the first URL from the post content. 664 * 665 * @return string The first link. 666 */ 667 function twentyeleven_get_first_url() { 668 $content = get_the_content(); 669 $has_url = function_exists( 'get_url_in_content' ) ? get_url_in_content( $content ) : false; 670 671 if ( ! $has_url ) { 672 $has_url = twentyeleven_url_grabber(); 673 } 674 675 /** This filter is documented in wp-includes/link-template.php */ 676 return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() ); 677 } 678 679 /** 680 * Return the URL for the first link found in the post content. 681 * 682 * @since Twenty Eleven 1.0 683 * 684 * @return string|bool URL or false when no link is present. 685 */ 686 function twentyeleven_url_grabber() { 687 if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) ) { 688 return false; 689 } 690 691 return esc_url_raw( $matches[1] ); 692 } 693 694 /** 695 * Count the number of footer sidebars to enable dynamic classes for the footer. 696 * 697 * @since Twenty Eleven 1.0 698 */ 699 function twentyeleven_footer_sidebar_class() { 700 $count = 0; 701 702 if ( is_active_sidebar( 'sidebar-3' ) ) { 703 ++$count; 704 } 705 706 if ( is_active_sidebar( 'sidebar-4' ) ) { 707 ++$count; 708 } 709 710 if ( is_active_sidebar( 'sidebar-5' ) ) { 711 ++$count; 712 } 713 714 $class = ''; 715 716 switch ( $count ) { 717 case '1': 718 $class = 'one'; 719 break; 720 case '2': 721 $class = 'two'; 722 break; 723 case '3': 724 $class = 'three'; 725 break; 726 } 727 728 if ( $class ) { 729 echo 'class="' . esc_attr( $class ) . '"'; 730 } 731 } 732 733 if ( ! function_exists( 'twentyeleven_comment' ) ) : 734 /** 735 * Template for comments and pingbacks. 736 * 737 * To override this walker in a child theme without modifying the comments template 738 * simply create your own twentyeleven_comment(), and that function will be used instead. 739 * 740 * Used as a callback by wp_list_comments() for displaying the comments. 741 * 742 * @since Twenty Eleven 1.0 743 * 744 * @param WP_Comment $comment The comment object. 745 * @param array $args An array of comment arguments. @see get_comment_reply_link() 746 * @param int $depth The depth of the comment. 747 */ 748 function twentyeleven_comment( $comment, $args, $depth ) { 749 $GLOBALS['comment'] = $comment; 750 switch ( $comment->comment_type ) : 751 case 'pingback': 752 case 'trackback': 753 ?> 754 <li class="post pingback"> 755 <p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p> 756 <?php 757 break; 758 default: 759 ?> 760 <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"> 761 <article id="comment-<?php comment_ID(); ?>" class="comment"> 762 <footer class="comment-meta"> 763 <div class="comment-author vcard"> 764 <?php 765 $avatar_size = 68; 766 767 if ( '0' !== $comment->comment_parent ) { 768 $avatar_size = 39; 769 } 770 771 echo get_avatar( $comment, $avatar_size ); 772 773 printf( 774 /* translators: 1: Comment author, 2: Date and time. */ 775 __( '%1$s on %2$s <span class="says">said:</span>', 'twentyeleven' ), 776 sprintf( '<span class="fn">%s</span>', get_comment_author_link() ), 777 sprintf( 778 '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>', 779 esc_url( get_comment_link( $comment->comment_ID ) ), 780 get_comment_time( 'c' ), 781 /* translators: 1: Date, 2: Time. */ 782 sprintf( __( '%1$s at %2$s', 'twentyeleven' ), get_comment_date(), get_comment_time() ) 783 ) 784 ); 785 ?> 786 787 <?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?> 788 </div><!-- .comment-author .vcard --> 789 790 <?php 791 $commenter = wp_get_current_commenter(); 792 if ( $commenter['comment_author_email'] ) { 793 $moderation_note = __( 'Your comment is awaiting moderation.', 'twentyeleven' ); 794 } else { 795 $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.', 'twentyeleven' ); 796 } 797 ?> 798 799 <?php if ( '0' === $comment->comment_approved ) : ?> 800 <em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em> 801 <br /> 802 <?php endif; ?> 803 804 </footer> 805 806 <div class="comment-content"><?php comment_text(); ?></div> 807 808 <div class="reply"> 809 <?php 810 comment_reply_link( 811 array_merge( 812 $args, 813 array( 814 'reply_text' => __( 'Reply <span>↓</span>', 'twentyeleven' ), 815 'depth' => $depth, 816 'max_depth' => $args['max_depth'], 817 ) 818 ) 819 ); 820 ?> 821 </div><!-- .reply --> 822 </article><!-- #comment-## --> 823 824 <?php 825 break; 826 endswitch; 827 } 828 endif; // twentyeleven_comment() 829 830 if ( ! function_exists( 'twentyeleven_posted_on' ) ) : 831 /** 832 * Print HTML with meta information for the current post-date/time and author. 833 * 834 * Create your own twentyeleven_posted_on to override in a child theme 835 * 836 * @since Twenty Eleven 1.0 837 */ 838 function twentyeleven_posted_on() { 839 printf( 840 /* 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. */ 841 __( '<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' ), 842 esc_url( get_permalink() ), 843 esc_attr( get_the_time() ), 844 esc_attr( get_the_date( 'c' ) ), 845 esc_html( get_the_date() ), 846 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), 847 /* translators: %s: Author display name. */ 848 esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ), 849 get_the_author() 850 ); 851 } 852 endif; 853 854 /** 855 * Add two classes to the array of body classes. 856 * 857 * The first is if the site has only had one author with published posts. 858 * The second is if a singular post being displayed 859 * 860 * @since Twenty Eleven 1.0 861 * 862 * @param array $classes Existing body classes. 863 * @return array The filtered array of body classes. 864 */ 865 function twentyeleven_body_classes( $classes ) { 866 867 if ( function_exists( 'is_multi_author' ) && ! is_multi_author() ) { 868 $classes[] = 'single-author'; 869 } 870 871 if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) ) { 872 $classes[] = 'singular'; 873 } 874 875 return $classes; 876 } 877 add_filter( 'body_class', 'twentyeleven_body_classes' ); 878 879 /** 880 * Retrieve the IDs for images in a gallery. 881 * 882 * @uses get_post_galleries() First, if available. Falls back to shortcode parsing, 883 * then as last option uses a get_posts() call. 884 * 885 * @since Twenty Eleven 1.6 886 * 887 * @return array List of image IDs from the post gallery. 888 */ 889 function twentyeleven_get_gallery_images() { 890 $images = array(); 891 892 if ( function_exists( 'get_post_galleries' ) ) { 893 $galleries = get_post_galleries( get_the_ID(), false ); 894 if ( isset( $galleries[0]['ids'] ) ) { 895 $images = explode( ',', $galleries[0]['ids'] ); 896 } 897 } else { 898 $pattern = get_shortcode_regex(); 899 preg_match( "/$pattern/s", get_the_content(), $match ); 900 $atts = shortcode_parse_atts( $match[3] ); 901 if ( isset( $atts['ids'] ) ) { 902 $images = explode( ',', $atts['ids'] ); 903 } 904 } 905 906 if ( ! $images ) { 907 $images = get_posts( 908 array( 909 'fields' => 'ids', 910 'numberposts' => 999, 911 'order' => 'ASC', 912 'orderby' => 'menu_order', 913 'post_mime_type' => 'image', 914 'post_parent' => get_the_ID(), 915 'post_type' => 'attachment', 916 ) 917 ); 918 } 919 920 return $images; 921 } 922 923 /** 924 * Modifies tag cloud widget arguments to display all tags in the same font size 925 * and use list format for better accessibility. 926 * 927 * @since Twenty Eleven 2.7 928 * 929 * @param array $args Arguments for tag cloud widget. 930 * @return array The filtered arguments for tag cloud widget. 931 */ 932 function twentyeleven_widget_tag_cloud_args( $args ) { 933 $args['largest'] = 22; 934 $args['smallest'] = 8; 935 $args['unit'] = 'pt'; 936 $args['format'] = 'list'; 937 938 return $args; 939 } 940 add_filter( 'widget_tag_cloud_args', 'twentyeleven_widget_tag_cloud_args' ); 941 942 if ( ! function_exists( 'wp_body_open' ) ) : 943 /** 944 * Fire the wp_body_open action. 945 * 946 * Added for backward compatibility to support pre-5.2.0 WordPress versions. 947 * 948 * @since Twenty Eleven 3.3 949 */ 950 function wp_body_open() { 951 /** 952 * Triggered after the opening <body> tag. 953 * 954 * @since Twenty Eleven 3.3 955 */ 956 do_action( 'wp_body_open' ); 957 } 958 endif; 959 960 /** 961 * Include a skip to content link at the top of the page so that users can bypass the menu. 962 * 963 * @since Twenty Eleven 3.4 964 */ 965 function twentyeleven_skip_link() { 966 echo '<div class="skip-link"><a class="assistive-text" href="#content">' . esc_html__( 'Skip to primary content', 'twentyeleven' ) . '</a></div>'; 967 if ( ! is_singular() ) { 968 echo '<div class="skip-link"><a class="assistive-text" href="#secondary">' . esc_html__( 'Skip to secondary content', 'twentyeleven' ) . '</a></div>'; 969 } 970 } 971 add_action( 'wp_body_open', 'twentyeleven_skip_link', 5 ); 972 973 if ( ! function_exists( 'wp_get_list_item_separator' ) ) : 974 /** 975 * Retrieves the list item separator based on the locale. 976 * 977 * Added for backward compatibility to support pre-6.0.0 WordPress versions. 978 * 979 * @since 6.0.0 980 */ 981 function wp_get_list_item_separator() { 982 /* translators: Used between list items, there is a space after the comma. */ 983 return __( ', ', 'twentyeleven' ); 984 } 985 endif;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Tue Dec 24 08:20:01 2024 | Cross-referenced by PHPXref |