PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/twentyeleven/functions.php

https://github.com/davodey/WordPress
PHP | 739 lines | 380 code | 68 blank | 291 comment | 50 complexity | 0236f463bd8cbc50581586cc6c71855d MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Twenty Eleven functions and definitions
  4. *
  5. * Sets up the theme and provides some helper functions. Some helper functions
  6. * are used in the theme as custom template tags. Others are attached to action and
  7. * filter hooks in WordPress to change core functionality.
  8. *
  9. * The first function, twentyeleven_setup(), sets up the theme by registering support
  10. * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
  11. *
  12. * When using a child theme (see http://codex.wordpress.org/Theme_Development and
  13. * http://codex.wordpress.org/Child_Themes), you can override certain functions
  14. * (those wrapped in a function_exists() call) by defining them first in your child theme's
  15. * functions.php file. The child theme's functions.php file is included before the parent
  16. * theme's file, so the child theme functions would be used.
  17. *
  18. * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
  19. * to a filter or action hook. The hook can be removed by using remove_action() or
  20. * remove_filter() and you can attach your own function to the hook.
  21. *
  22. * We can remove the parent theme's hook only after it is attached, which means we need to
  23. * wait until setting up the child theme:
  24. *
  25. * <code>
  26. * add_action( 'after_setup_theme', 'my_child_theme_setup' );
  27. * function my_child_theme_setup() {
  28. * // We are providing our own filter for excerpt_length (or using the unfiltered value)
  29. * remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );
  30. * ...
  31. * }
  32. * </code>
  33. *
  34. * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
  35. *
  36. * @package WordPress
  37. * @subpackage Twenty_Eleven
  38. * @since Twenty Eleven 1.0
  39. */
  40. // Set the content width based on the theme's design and stylesheet.
  41. if ( ! isset( $content_width ) )
  42. $content_width = 584;
  43. /*
  44. * Tell WordPress to run twentyeleven_setup() when the 'after_setup_theme' hook is run.
  45. */
  46. add_action( 'after_setup_theme', 'twentyeleven_setup' );
  47. if ( ! function_exists( 'twentyeleven_setup' ) ):
  48. /**
  49. * Set up theme defaults and registers support for various WordPress features.
  50. *
  51. * Note that this function is hooked into the after_setup_theme hook, which runs
  52. * before the init hook. The init hook is too late for some features, such as indicating
  53. * support post thumbnails.
  54. *
  55. * To override twentyeleven_setup() in a child theme, add your own twentyeleven_setup to your child theme's
  56. * functions.php file.
  57. *
  58. * @uses load_theme_textdomain() For translation/localization support.
  59. * @uses add_editor_style() To style the visual editor.
  60. * @uses add_theme_support() To add support for post thumbnails, automatic feed links, custom headers
  61. * and backgrounds, and post formats.
  62. * @uses register_nav_menus() To add support for navigation menus.
  63. * @uses register_default_headers() To register the default custom header images provided with the theme.
  64. * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  65. *
  66. * @since Twenty Eleven 1.0
  67. */
  68. function twentyeleven_setup() {
  69. /*
  70. * Make Twenty Eleven available for translation.
  71. * Translations can be added to the /languages/ directory.
  72. * If you're building a theme based on Twenty Eleven, use
  73. * a find and replace to change 'twentyeleven' to the name
  74. * of your theme in all the template files.
  75. */
  76. load_theme_textdomain( 'twentyeleven', get_template_directory() . '/languages' );
  77. // This theme styles the visual editor with editor-style.css to match the theme style.
  78. add_editor_style();
  79. // Load up our theme options page and related code.
  80. require( get_template_directory() . '/inc/theme-options.php' );
  81. // Grab Twenty Eleven's Ephemera widget.
  82. require( get_template_directory() . '/inc/widgets.php' );
  83. // Add default posts and comments RSS feed links to <head>.
  84. add_theme_support( 'automatic-feed-links' );
  85. // This theme uses wp_nav_menu() in one location.
  86. register_nav_menu( 'primary', __( 'Primary Menu', 'twentyeleven' ) );
  87. // Add support for a variety of post formats
  88. add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) );
  89. $theme_options = twentyeleven_get_theme_options();
  90. if ( 'dark' == $theme_options['color_scheme'] )
  91. $default_background_color = '1d1d1d';
  92. else
  93. $default_background_color = 'e2e2e2';
  94. // Add support for custom backgrounds.
  95. add_theme_support( 'custom-background', array(
  96. /*
  97. * Let WordPress know what our default background color is.
  98. * This is dependent on our current color scheme.
  99. */
  100. 'default-color' => $default_background_color,
  101. ) );
  102. // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images
  103. add_theme_support( 'post-thumbnails' );
  104. // Add support for custom headers.
  105. $custom_header_support = array(
  106. // The default header text color.
  107. 'default-text-color' => '000',
  108. // The height and width of our custom header.
  109. /**
  110. * Filter the Twenty Eleven default header image width.
  111. *
  112. * @since Twenty Eleven 1.0
  113. *
  114. * @param int The default header image width in pixels. Default 1000.
  115. */
  116. 'width' => apply_filters( 'twentyeleven_header_image_width', 1000 ),
  117. /**
  118. * Filter the Twenty Eleven default header image height.
  119. *
  120. * @since Twenty Eleven 1.0
  121. *
  122. * @param int The default header image height in pixels. Default 288.
  123. */
  124. 'height' => apply_filters( 'twentyeleven_header_image_height', 288 ),
  125. // Support flexible heights.
  126. 'flex-height' => true,
  127. // Random image rotation by default.
  128. 'random-default' => true,
  129. // Callback for styling the header.
  130. 'wp-head-callback' => 'twentyeleven_header_style',
  131. // Callback for styling the header preview in the admin.
  132. 'admin-head-callback' => 'twentyeleven_admin_header_style',
  133. // Callback used to display the header preview in the admin.
  134. 'admin-preview-callback' => 'twentyeleven_admin_header_image',
  135. );
  136. add_theme_support( 'custom-header', $custom_header_support );
  137. if ( ! function_exists( 'get_custom_header' ) ) {
  138. // This is all for compatibility with versions of WordPress prior to 3.4.
  139. define( 'HEADER_TEXTCOLOR', $custom_header_support['default-text-color'] );
  140. define( 'HEADER_IMAGE', '' );
  141. define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] );
  142. define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] );
  143. add_custom_image_header( $custom_header_support['wp-head-callback'], $custom_header_support['admin-head-callback'], $custom_header_support['admin-preview-callback'] );
  144. add_custom_background();
  145. }
  146. /*
  147. * We'll be using post thumbnails for custom header images on posts and pages.
  148. * We want them to be the size of the header image that we just defined.
  149. * Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
  150. */
  151. set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true );
  152. /*
  153. * Add Twenty Eleven's custom image sizes.
  154. * Used for large feature (header) images.
  155. */
  156. add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true );
  157. // Used for featured posts if a large-feature doesn't exist.
  158. add_image_size( 'small-feature', 500, 300 );
  159. // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
  160. register_default_headers( array(
  161. 'wheel' => array(
  162. 'url' => '%s/images/headers/wheel.jpg',
  163. 'thumbnail_url' => '%s/images/headers/wheel-thumbnail.jpg',
  164. /* translators: header image description */
  165. 'description' => __( 'Wheel', 'twentyeleven' )
  166. ),
  167. 'shore' => array(
  168. 'url' => '%s/images/headers/shore.jpg',
  169. 'thumbnail_url' => '%s/images/headers/shore-thumbnail.jpg',
  170. /* translators: header image description */
  171. 'description' => __( 'Shore', 'twentyeleven' )
  172. ),
  173. 'trolley' => array(
  174. 'url' => '%s/images/headers/trolley.jpg',
  175. 'thumbnail_url' => '%s/images/headers/trolley-thumbnail.jpg',
  176. /* translators: header image description */
  177. 'description' => __( 'Trolley', 'twentyeleven' )
  178. ),
  179. 'pine-cone' => array(
  180. 'url' => '%s/images/headers/pine-cone.jpg',
  181. 'thumbnail_url' => '%s/images/headers/pine-cone-thumbnail.jpg',
  182. /* translators: header image description */
  183. 'description' => __( 'Pine Cone', 'twentyeleven' )
  184. ),
  185. 'chessboard' => array(
  186. 'url' => '%s/images/headers/chessboard.jpg',
  187. 'thumbnail_url' => '%s/images/headers/chessboard-thumbnail.jpg',
  188. /* translators: header image description */
  189. 'description' => __( 'Chessboard', 'twentyeleven' )
  190. ),
  191. 'lanterns' => array(
  192. 'url' => '%s/images/headers/lanterns.jpg',
  193. 'thumbnail_url' => '%s/images/headers/lanterns-thumbnail.jpg',
  194. /* translators: header image description */
  195. 'description' => __( 'Lanterns', 'twentyeleven' )
  196. ),
  197. 'willow' => array(
  198. 'url' => '%s/images/headers/willow.jpg',
  199. 'thumbnail_url' => '%s/images/headers/willow-thumbnail.jpg',
  200. /* translators: header image description */
  201. 'description' => __( 'Willow', 'twentyeleven' )
  202. ),
  203. 'hanoi' => array(
  204. 'url' => '%s/images/headers/hanoi.jpg',
  205. 'thumbnail_url' => '%s/images/headers/hanoi-thumbnail.jpg',
  206. /* translators: header image description */
  207. 'description' => __( 'Hanoi Plant', 'twentyeleven' )
  208. )
  209. ) );
  210. }
  211. endif; // twentyeleven_setup
  212. if ( ! function_exists( 'twentyeleven_header_style' ) ) :
  213. /**
  214. * Styles the header image and text displayed on the blog.
  215. *
  216. * @since Twenty Eleven 1.0
  217. */
  218. function twentyeleven_header_style() {
  219. $text_color = get_header_textcolor();
  220. // If no custom options for text are set, let's bail.
  221. if ( $text_color == HEADER_TEXTCOLOR )
  222. return;
  223. // If we get this far, we have custom styles. Let's do this.
  224. ?>
  225. <style type="text/css" id="twentyeleven-header-css">
  226. <?php
  227. // Has the text been hidden?
  228. if ( 'blank' == $text_color ) :
  229. ?>
  230. #site-title,
  231. #site-description {
  232. position: absolute !important;
  233. clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
  234. clip: rect(1px, 1px, 1px, 1px);
  235. }
  236. <?php
  237. // If the user has set a custom color for the text use that
  238. else :
  239. ?>
  240. #site-title a,
  241. #site-description {
  242. color: #<?php echo $text_color; ?> !important;
  243. }
  244. <?php endif; ?>
  245. </style>
  246. <?php
  247. }
  248. endif; // twentyeleven_header_style
  249. if ( ! function_exists( 'twentyeleven_admin_header_style' ) ) :
  250. /**
  251. * Styles the header image displayed on the Appearance > Header admin panel.
  252. *
  253. * Referenced via add_theme_support('custom-header') in twentyeleven_setup().
  254. *
  255. * @since Twenty Eleven 1.0
  256. */
  257. function twentyeleven_admin_header_style() {
  258. ?>
  259. <style type="text/css" id="twentyeleven-admin-header-css">
  260. .appearance_page_custom-header #headimg {
  261. border: none;
  262. }
  263. #headimg h1,
  264. #desc {
  265. font-family: "Helvetica Neue", Arial, Helvetica, "Nimbus Sans L", sans-serif;
  266. }
  267. #headimg h1 {
  268. margin: 0;
  269. }
  270. #headimg h1 a {
  271. font-size: 32px;
  272. line-height: 36px;
  273. text-decoration: none;
  274. }
  275. #desc {
  276. font-size: 14px;
  277. line-height: 23px;
  278. padding: 0 0 3em;
  279. }
  280. <?php
  281. // If the user has set a custom color for the text use that
  282. if ( get_header_textcolor() != HEADER_TEXTCOLOR ) :
  283. ?>
  284. #site-title a,
  285. #site-description {
  286. color: #<?php echo get_header_textcolor(); ?>;
  287. }
  288. <?php endif; ?>
  289. #headimg img {
  290. max-width: 1000px;
  291. height: auto;
  292. width: 100%;
  293. }
  294. </style>
  295. <?php
  296. }
  297. endif; // twentyeleven_admin_header_style
  298. if ( ! function_exists( 'twentyeleven_admin_header_image' ) ) :
  299. /**
  300. * Custom header image markup displayed on the Appearance > Header admin panel.
  301. *
  302. * Referenced via add_theme_support('custom-header') in twentyeleven_setup().
  303. *
  304. * @since Twenty Eleven 1.0
  305. */
  306. function twentyeleven_admin_header_image() { ?>
  307. <div id="headimg">
  308. <?php
  309. $color = get_header_textcolor();
  310. $image = get_header_image();
  311. if ( $color && $color != 'blank' )
  312. $style = ' style="color:#' . $color . '"';
  313. else
  314. $style = ' style="display:none"';
  315. ?>
  316. <h1 class="displaying-header-text"><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
  317. <div id="desc" class="displaying-header-text"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
  318. <?php if ( $image ) : ?>
  319. <img src="<?php echo esc_url( $image ); ?>" alt="" />
  320. <?php endif; ?>
  321. </div>
  322. <?php }
  323. endif; // twentyeleven_admin_header_image
  324. /**
  325. * Set the post excerpt length to 40 words.
  326. *
  327. * To override this length in a child theme, remove
  328. * the filter and add your own function tied to
  329. * the excerpt_length filter hook.
  330. *
  331. * @since Twenty Eleven 1.0
  332. *
  333. * @param int $length The number of excerpt characters.
  334. * @return int The filtered number of characters.
  335. */
  336. function twentyeleven_excerpt_length( $length ) {
  337. return 40;
  338. }
  339. add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );
  340. if ( ! function_exists( 'twentyeleven_continue_reading_link' ) ) :
  341. /**
  342. * Return a "Continue Reading" link for excerpts
  343. *
  344. * @since Twenty Eleven 1.0
  345. *
  346. * @return string The "Continue Reading" HTML link.
  347. */
  348. function twentyeleven_continue_reading_link() {
  349. return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) . '</a>';
  350. }
  351. endif; // twentyeleven_continue_reading_link
  352. /**
  353. * Replace "[...]" in the Read More link with an ellipsis.
  354. *
  355. * The "[...]" is appended to automatically generated excerpts.
  356. *
  357. * To override this in a child theme, remove the filter and add your own
  358. * function tied to the excerpt_more filter hook.
  359. *
  360. * @since Twenty Eleven 1.0
  361. *
  362. * @param string $more The Read More text.
  363. * @return The filtered Read More text.
  364. */
  365. function twentyeleven_auto_excerpt_more( $more ) {
  366. return ' &hellip;' . twentyeleven_continue_reading_link();
  367. }
  368. add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' );
  369. /**
  370. * Add a pretty "Continue Reading" link to custom post excerpts.
  371. *
  372. * To override this link in a child theme, remove the filter and add your own
  373. * function tied to the get_the_excerpt filter hook.
  374. *
  375. * @since Twenty Eleven 1.0
  376. *
  377. * @param string $output The "Continue Reading" link.
  378. * @return string The filtered "Continue Reading" link.
  379. */
  380. function twentyeleven_custom_excerpt_more( $output ) {
  381. if ( has_excerpt() && ! is_attachment() ) {
  382. $output .= twentyeleven_continue_reading_link();
  383. }
  384. return $output;
  385. }
  386. add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );
  387. /**
  388. * Show a home link for the wp_nav_menu() fallback, wp_page_menu().
  389. *
  390. * @since Twenty Eleven 1.0
  391. *
  392. * @param array $args The page menu arguments. @see wp_page_menu()
  393. * @return array The filtered page menu arguments.
  394. */
  395. function twentyeleven_page_menu_args( $args ) {
  396. if ( ! isset( $args['show_home'] ) )
  397. $args['show_home'] = true;
  398. return $args;
  399. }
  400. add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' );
  401. /**
  402. * Register sidebars and widgetized areas.
  403. *
  404. * Also register the default Epherma widget.
  405. *
  406. * @since Twenty Eleven 1.0
  407. */
  408. function twentyeleven_widgets_init() {
  409. register_widget( 'Twenty_Eleven_Ephemera_Widget' );
  410. register_sidebar( array(
  411. 'name' => __( 'Main Sidebar', 'twentyeleven' ),
  412. 'id' => 'sidebar-1',
  413. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  414. 'after_widget' => "</aside>",
  415. 'before_title' => '<h3 class="widget-title">',
  416. 'after_title' => '</h3>',
  417. ) );
  418. register_sidebar( array(
  419. 'name' => __( 'Showcase Sidebar', 'twentyeleven' ),
  420. 'id' => 'sidebar-2',
  421. 'description' => __( 'The sidebar for the optional Showcase Template', 'twentyeleven' ),
  422. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  423. 'after_widget' => "</aside>",
  424. 'before_title' => '<h3 class="widget-title">',
  425. 'after_title' => '</h3>',
  426. ) );
  427. register_sidebar( array(
  428. 'name' => __( 'Footer Area One', 'twentyeleven' ),
  429. 'id' => 'sidebar-3',
  430. 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ),
  431. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  432. 'after_widget' => "</aside>",
  433. 'before_title' => '<h3 class="widget-title">',
  434. 'after_title' => '</h3>',
  435. ) );
  436. register_sidebar( array(
  437. 'name' => __( 'Footer Area Two', 'twentyeleven' ),
  438. 'id' => 'sidebar-4',
  439. 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ),
  440. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  441. 'after_widget' => "</aside>",
  442. 'before_title' => '<h3 class="widget-title">',
  443. 'after_title' => '</h3>',
  444. ) );
  445. register_sidebar( array(
  446. 'name' => __( 'Footer Area Three', 'twentyeleven' ),
  447. 'id' => 'sidebar-5',
  448. 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ),
  449. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  450. 'after_widget' => "</aside>",
  451. 'before_title' => '<h3 class="widget-title">',
  452. 'after_title' => '</h3>',
  453. ) );
  454. }
  455. add_action( 'widgets_init', 'twentyeleven_widgets_init' );
  456. if ( ! function_exists( 'twentyeleven_content_nav' ) ) :
  457. /**
  458. * Display navigation to next/previous pages when applicable.
  459. *
  460. * @since Twenty Eleven 1.0
  461. *
  462. * @param string $html_id The HTML id attribute.
  463. */
  464. function twentyeleven_content_nav( $html_id ) {
  465. global $wp_query;
  466. if ( $wp_query->max_num_pages > 1 ) : ?>
  467. <nav id="<?php echo esc_attr( $html_id ); ?>">
  468. <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
  469. <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyeleven' ) ); ?></div>
  470. <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?></div>
  471. </nav><!-- #nav-above -->
  472. <?php endif;
  473. }
  474. endif; // twentyeleven_content_nav
  475. /**
  476. * Return the first link from the post content. If none found, the
  477. * post permalink is used as a fallback.
  478. *
  479. * @since Twenty Eleven 1.0
  480. *
  481. * @uses get_url_in_content() to get the first URL from the post content.
  482. *
  483. * @return string The first link.
  484. */
  485. function twentyeleven_get_first_url() {
  486. $content = get_the_content();
  487. $has_url = function_exists( 'get_url_in_content' ) ? get_url_in_content( $content ) : false;
  488. if ( ! $has_url )
  489. $has_url = twentyeleven_url_grabber();
  490. /** This filter is documented in wp-includes/link-template.php */
  491. return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
  492. }
  493. /**
  494. * Return the URL for the first link found in the post content.
  495. *
  496. * @since Twenty Eleven 1.0
  497. *
  498. * @return string|bool URL or false when no link is present.
  499. */
  500. function twentyeleven_url_grabber() {
  501. if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) )
  502. return false;
  503. return esc_url_raw( $matches[1] );
  504. }
  505. /**
  506. * Count the number of footer sidebars to enable dynamic classes for the footer.
  507. *
  508. * @since Twenty Eleven 1.0
  509. */
  510. function twentyeleven_footer_sidebar_class() {
  511. $count = 0;
  512. if ( is_active_sidebar( 'sidebar-3' ) )
  513. $count++;
  514. if ( is_active_sidebar( 'sidebar-4' ) )
  515. $count++;
  516. if ( is_active_sidebar( 'sidebar-5' ) )
  517. $count++;
  518. $class = '';
  519. switch ( $count ) {
  520. case '1':
  521. $class = 'one';
  522. break;
  523. case '2':
  524. $class = 'two';
  525. break;
  526. case '3':
  527. $class = 'three';
  528. break;
  529. }
  530. if ( $class )
  531. echo 'class="' . $class . '"';
  532. }
  533. if ( ! function_exists( 'twentyeleven_comment' ) ) :
  534. /**
  535. * Template for comments and pingbacks.
  536. *
  537. * To override this walker in a child theme without modifying the comments template
  538. * simply create your own twentyeleven_comment(), and that function will be used instead.
  539. *
  540. * Used as a callback by wp_list_comments() for displaying the comments.
  541. *
  542. * @since Twenty Eleven 1.0
  543. *
  544. * @param object $comment The comment object.
  545. * @param array $args An array of comment arguments. @see get_comment_reply_link()
  546. * @param int $depth The depth of the comment.
  547. */
  548. function twentyeleven_comment( $comment, $args, $depth ) {
  549. $GLOBALS['comment'] = $comment;
  550. switch ( $comment->comment_type ) :
  551. case 'pingback' :
  552. case 'trackback' :
  553. ?>
  554. <li class="post pingback">
  555. <p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p>
  556. <?php
  557. break;
  558. default :
  559. ?>
  560. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  561. <article id="comment-<?php comment_ID(); ?>" class="comment">
  562. <footer class="comment-meta">
  563. <div class="comment-author vcard">
  564. <?php
  565. $avatar_size = 68;
  566. if ( '0' != $comment->comment_parent )
  567. $avatar_size = 39;
  568. echo get_avatar( $comment, $avatar_size );
  569. /* translators: 1: comment author, 2: date and time */
  570. printf( __( '%1$s on %2$s <span class="says">said:</span>', 'twentyeleven' ),
  571. sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
  572. sprintf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
  573. esc_url( get_comment_link( $comment->comment_ID ) ),
  574. get_comment_time( 'c' ),
  575. /* translators: 1: date, 2: time */
  576. sprintf( __( '%1$s at %2$s', 'twentyeleven' ), get_comment_date(), get_comment_time() )
  577. )
  578. );
  579. ?>
  580. <?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?>
  581. </div><!-- .comment-author .vcard -->
  582. <?php if ( $comment->comment_approved == '0' ) : ?>
  583. <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyeleven' ); ?></em>
  584. <br />
  585. <?php endif; ?>
  586. </footer>
  587. <div class="comment-content"><?php comment_text(); ?></div>
  588. <div class="reply">
  589. <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span>&darr;</span>', 'twentyeleven' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  590. </div><!-- .reply -->
  591. </article><!-- #comment-## -->
  592. <?php
  593. break;
  594. endswitch;
  595. }
  596. endif; // ends check for twentyeleven_comment()
  597. if ( ! function_exists( 'twentyeleven_posted_on' ) ) :
  598. /**
  599. * Print HTML with meta information for the current post-date/time and author.
  600. *
  601. * Create your own twentyeleven_posted_on to override in a child theme
  602. *
  603. * @since Twenty Eleven 1.0
  604. */
  605. function twentyeleven_posted_on() {
  606. printf( __( '<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' ),
  607. esc_url( get_permalink() ),
  608. esc_attr( get_the_time() ),
  609. esc_attr( get_the_date( 'c' ) ),
  610. esc_html( get_the_date() ),
  611. esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  612. esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ),
  613. get_the_author()
  614. );
  615. }
  616. endif;
  617. /**
  618. * Add two classes to the array of body classes.
  619. *
  620. * The first is if the site has only had one author with published posts.
  621. * The second is if a singular post being displayed
  622. *
  623. * @since Twenty Eleven 1.0
  624. *
  625. * @param array $classes Existing body classes.
  626. * @return array The filtered array of body classes.
  627. */
  628. function twentyeleven_body_classes( $classes ) {
  629. if ( function_exists( 'is_multi_author' ) && ! is_multi_author() )
  630. $classes[] = 'single-author';
  631. if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) )
  632. $classes[] = 'singular';
  633. return $classes;
  634. }
  635. add_filter( 'body_class', 'twentyeleven_body_classes' );
  636. /**
  637. * Retrieve the IDs for images in a gallery.
  638. *
  639. * @uses get_post_galleries() First, if available. Falls back to shortcode parsing,
  640. * then as last option uses a get_posts() call.
  641. *
  642. * @since Twenty Eleven 1.6
  643. *
  644. * @return array List of image IDs from the post gallery.
  645. */
  646. function twentyeleven_get_gallery_images() {
  647. $images = array();
  648. if ( function_exists( 'get_post_galleries' ) ) {
  649. $galleries = get_post_galleries( get_the_ID(), false );
  650. if ( isset( $galleries[0]['ids'] ) )
  651. $images = explode( ',', $galleries[0]['ids'] );
  652. } else {
  653. $pattern = get_shortcode_regex();
  654. preg_match( "/$pattern/s", get_the_content(), $match );
  655. $atts = shortcode_parse_atts( $match[3] );
  656. if ( isset( $atts['ids'] ) )
  657. $images = explode( ',', $atts['ids'] );
  658. }
  659. if ( ! $images ) {
  660. $images = get_posts( array(
  661. 'fields' => 'ids',
  662. 'numberposts' => 999,
  663. 'order' => 'ASC',
  664. 'orderby' => 'menu_order',
  665. 'post_mime_type' => 'image',
  666. 'post_parent' => get_the_ID(),
  667. 'post_type' => 'attachment',
  668. ) );
  669. }
  670. return $images;
  671. }