[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-content/themes/twentyeleven/ -> functions.php (source)

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


Generated: Tue Mar 19 01:00:02 2024 Cross-referenced by PHPXref 0.7.1