wp/wp-content/themes/twentythirteen/functions.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 10 372f2766ea20
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    26 /*
    26 /*
    27  * Set up the content width value based on the theme's design.
    27  * Set up the content width value based on the theme's design.
    28  *
    28  *
    29  * @see twentythirteen_content_width() for template-specific adjustments.
    29  * @see twentythirteen_content_width() for template-specific adjustments.
    30  */
    30  */
    31 if ( ! isset( $content_width ) )
    31 if ( ! isset( $content_width ) ) {
    32 	$content_width = 604;
    32 	$content_width = 604;
       
    33 }
    33 
    34 
    34 /**
    35 /**
    35  * Add support for a custom header image.
    36  * Add support for a custom header image.
    36  */
    37  */
    37 require get_template_directory() . '/inc/custom-header.php';
    38 require get_template_directory() . '/inc/custom-header.php';
    38 
    39 
    39 /**
    40 /**
    40  * Twenty Thirteen only works in WordPress 3.6 or later.
    41  * Twenty Thirteen only works in WordPress 3.6 or later.
    41  */
    42  */
    42 if ( version_compare( $GLOBALS['wp_version'], '3.6-alpha', '<' ) )
    43 if ( version_compare( $GLOBALS['wp_version'], '3.6-alpha', '<' ) ) {
    43 	require get_template_directory() . '/inc/back-compat.php';
    44 	require get_template_directory() . '/inc/back-compat.php';
       
    45 }
    44 
    46 
    45 /**
    47 /**
    46  * Twenty Thirteen setup.
    48  * Twenty Thirteen setup.
    47  *
    49  *
    48  * Sets up theme defaults and registers the various WordPress features that
    50  * Sets up theme defaults and registers the various WordPress features that
    59  */
    61  */
    60 function twentythirteen_setup() {
    62 function twentythirteen_setup() {
    61 	/*
    63 	/*
    62 	 * Makes Twenty Thirteen available for translation.
    64 	 * Makes Twenty Thirteen available for translation.
    63 	 *
    65 	 *
    64 	 * Translations can be added to the /languages/ directory.
    66 	 * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentythirteen
    65 	 * If you're building a theme based on Twenty Thirteen, use a find and
    67 	 * If you're building a theme based on Twenty Thirteen, use a find and
    66 	 * replace to change 'twentythirteen' to the name of your theme in all
    68 	 * replace to change 'twentythirteen' to the name of your theme in all
    67 	 * template files.
    69 	 * template files.
    68 	 */
    70 	 */
    69 	load_theme_textdomain( 'twentythirteen', get_template_directory() . '/languages' );
    71 	load_theme_textdomain( 'twentythirteen' );
    70 
    72 
    71 	/*
    73 	/*
    72 	 * This theme styles the visual editor to resemble the theme style,
    74 	 * This theme styles the visual editor to resemble the theme style,
    73 	 * specifically font, colors, icons, and column width.
    75 	 * specifically font, colors, icons, and column width.
    74 	 */
    76 	 */
    79 
    81 
    80 	/*
    82 	/*
    81 	 * Switches default core markup for search form, comment form,
    83 	 * Switches default core markup for search form, comment form,
    82 	 * and comments to output valid HTML5.
    84 	 * and comments to output valid HTML5.
    83 	 */
    85 	 */
    84 	add_theme_support( 'html5', array(
    86 	add_theme_support(
    85 		'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
    87 		'html5', array(
    86 	) );
    88 			'search-form',
       
    89 			'comment-form',
       
    90 			'comment-list',
       
    91 			'gallery',
       
    92 			'caption',
       
    93 		)
       
    94 	);
    87 
    95 
    88 	/*
    96 	/*
    89 	 * This theme supports all available post formats by default.
    97 	 * This theme supports all available post formats by default.
    90 	 * See https://codex.wordpress.org/Post_Formats
    98 	 * See https://codex.wordpress.org/Post_Formats
    91 	 */
    99 	 */
    92 	add_theme_support( 'post-formats', array(
   100 	add_theme_support(
    93 		'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video'
   101 		'post-formats', array(
    94 	) );
   102 			'aside',
       
   103 			'audio',
       
   104 			'chat',
       
   105 			'gallery',
       
   106 			'image',
       
   107 			'link',
       
   108 			'quote',
       
   109 			'status',
       
   110 			'video',
       
   111 		)
       
   112 	);
    95 
   113 
    96 	// This theme uses wp_nav_menu() in one location.
   114 	// This theme uses wp_nav_menu() in one location.
    97 	register_nav_menu( 'primary', __( 'Navigation Menu', 'twentythirteen' ) );
   115 	register_nav_menu( 'primary', __( 'Navigation Menu', 'twentythirteen' ) );
    98 
   116 
    99 	/*
   117 	/*
   103 	add_theme_support( 'post-thumbnails' );
   121 	add_theme_support( 'post-thumbnails' );
   104 	set_post_thumbnail_size( 604, 270, true );
   122 	set_post_thumbnail_size( 604, 270, true );
   105 
   123 
   106 	// This theme uses its own gallery styles.
   124 	// This theme uses its own gallery styles.
   107 	add_filter( 'use_default_gallery_style', '__return_false' );
   125 	add_filter( 'use_default_gallery_style', '__return_false' );
       
   126 
       
   127 	// Indicate widget sidebars can use selective refresh in the Customizer.
       
   128 	add_theme_support( 'customize-selective-refresh-widgets' );
   108 }
   129 }
   109 add_action( 'after_setup_theme', 'twentythirteen_setup' );
   130 add_action( 'after_setup_theme', 'twentythirteen_setup' );
   110 
   131 
   111 /**
   132 /**
   112  * Return the Google font stylesheet URL, if available.
   133  * Return the Google font stylesheet URL, if available.
   134 	$bitter = _x( 'on', 'Bitter font: on or off', 'twentythirteen' );
   155 	$bitter = _x( 'on', 'Bitter font: on or off', 'twentythirteen' );
   135 
   156 
   136 	if ( 'off' !== $source_sans_pro || 'off' !== $bitter ) {
   157 	if ( 'off' !== $source_sans_pro || 'off' !== $bitter ) {
   137 		$font_families = array();
   158 		$font_families = array();
   138 
   159 
   139 		if ( 'off' !== $source_sans_pro )
   160 		if ( 'off' !== $source_sans_pro ) {
   140 			$font_families[] = 'Source Sans Pro:300,400,700,300italic,400italic,700italic';
   161 			$font_families[] = 'Source Sans Pro:300,400,700,300italic,400italic,700italic';
   141 
   162 		}
   142 		if ( 'off' !== $bitter )
   163 
       
   164 		if ( 'off' !== $bitter ) {
   143 			$font_families[] = 'Bitter:400,700';
   165 			$font_families[] = 'Bitter:400,700';
       
   166 		}
   144 
   167 
   145 		$query_args = array(
   168 		$query_args = array(
   146 			'family' => urlencode( implode( '|', $font_families ) ),
   169 			'family' => urlencode( implode( '|', $font_families ) ),
   147 			'subset' => urlencode( 'latin,latin-ext' ),
   170 			'subset' => urlencode( 'latin,latin-ext' ),
   148 		);
   171 		);
   149 		$fonts_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' );
   172 		$fonts_url  = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
   150 	}
   173 	}
   151 
   174 
   152 	return $fonts_url;
   175 	return $fonts_url;
   153 }
   176 }
   154 
   177 
   160 function twentythirteen_scripts_styles() {
   183 function twentythirteen_scripts_styles() {
   161 	/*
   184 	/*
   162 	 * Adds JavaScript to pages with the comment form to support
   185 	 * Adds JavaScript to pages with the comment form to support
   163 	 * sites with threaded comments (when in use).
   186 	 * sites with threaded comments (when in use).
   164 	 */
   187 	 */
   165 	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
   188 	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
   166 		wp_enqueue_script( 'comment-reply' );
   189 		wp_enqueue_script( 'comment-reply' );
       
   190 	}
   167 
   191 
   168 	// Adds Masonry to handle vertical alignment of footer widgets.
   192 	// Adds Masonry to handle vertical alignment of footer widgets.
   169 	if ( is_active_sidebar( 'sidebar-1' ) )
   193 	if ( is_active_sidebar( 'sidebar-1' ) ) {
   170 		wp_enqueue_script( 'jquery-masonry' );
   194 		wp_enqueue_script( 'jquery-masonry' );
       
   195 	}
   171 
   196 
   172 	// Loads JavaScript file with functionality specific to Twenty Thirteen.
   197 	// Loads JavaScript file with functionality specific to Twenty Thirteen.
   173 	wp_enqueue_script( 'twentythirteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20150330', true );
   198 	wp_enqueue_script( 'twentythirteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20160717', true );
   174 
   199 
   175 	// Add Source Sans Pro and Bitter fonts, used in the main stylesheet.
   200 	// Add Source Sans Pro and Bitter fonts, used in the main stylesheet.
   176 	wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), null );
   201 	wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), null );
   177 
   202 
   178 	// Add Genericons font, used in the main stylesheet.
   203 	// Add Genericons font, used in the main stylesheet.
   186 	wp_style_add_data( 'twentythirteen-ie', 'conditional', 'lt IE 9' );
   211 	wp_style_add_data( 'twentythirteen-ie', 'conditional', 'lt IE 9' );
   187 }
   212 }
   188 add_action( 'wp_enqueue_scripts', 'twentythirteen_scripts_styles' );
   213 add_action( 'wp_enqueue_scripts', 'twentythirteen_scripts_styles' );
   189 
   214 
   190 /**
   215 /**
       
   216  * Add preconnect for Google Fonts.
       
   217  *
       
   218  * @since Twenty Thirteen 2.1
       
   219  *
       
   220  * @param array   $urls          URLs to print for resource hints.
       
   221  * @param string  $relation_type The relation type the URLs are printed.
       
   222  * @return array URLs to print for resource hints.
       
   223  */
       
   224 function twentythirteen_resource_hints( $urls, $relation_type ) {
       
   225 	if ( wp_style_is( 'twentythirteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
       
   226 		if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
       
   227 			$urls[] = array(
       
   228 				'href' => 'https://fonts.gstatic.com',
       
   229 				'crossorigin',
       
   230 			);
       
   231 		} else {
       
   232 			$urls[] = 'https://fonts.gstatic.com';
       
   233 		}
       
   234 	}
       
   235 
       
   236 	return $urls;
       
   237 }
       
   238 add_filter( 'wp_resource_hints', 'twentythirteen_resource_hints', 10, 2 );
       
   239 
       
   240 /**
   191  * Filter the page title.
   241  * Filter the page title.
   192  *
   242  *
   193  * Creates a nicely formatted and more specific title element text for output
   243  * Creates a nicely formatted and more specific title element text for output
   194  * in head of document, based on current view.
   244  * in head of document, based on current view.
   195  *
   245  *
   200  * @return string The filtered title.
   250  * @return string The filtered title.
   201  */
   251  */
   202 function twentythirteen_wp_title( $title, $sep ) {
   252 function twentythirteen_wp_title( $title, $sep ) {
   203 	global $paged, $page;
   253 	global $paged, $page;
   204 
   254 
   205 	if ( is_feed() )
   255 	if ( is_feed() ) {
   206 		return $title;
   256 		return $title;
       
   257 	}
   207 
   258 
   208 	// Add the site name.
   259 	// Add the site name.
   209 	$title .= get_bloginfo( 'name', 'display' );
   260 	$title .= get_bloginfo( 'name', 'display' );
   210 
   261 
   211 	// Add the site description for the home/front page.
   262 	// Add the site description for the home/front page.
   212 	$site_description = get_bloginfo( 'description', 'display' );
   263 	$site_description = get_bloginfo( 'description', 'display' );
   213 	if ( $site_description && ( is_home() || is_front_page() ) )
   264 	if ( $site_description && ( is_home() || is_front_page() ) ) {
   214 		$title = "$title $sep $site_description";
   265 		$title = "$title $sep $site_description";
       
   266 	}
   215 
   267 
   216 	// Add a page number if necessary.
   268 	// Add a page number if necessary.
   217 	if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() )
   269 	if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
   218 		$title = "$title $sep " . sprintf( __( 'Page %s', 'twentythirteen' ), max( $paged, $page ) );
   270 		$title = "$title $sep " . sprintf( __( 'Page %s', 'twentythirteen' ), max( $paged, $page ) );
       
   271 	}
   219 
   272 
   220 	return $title;
   273 	return $title;
   221 }
   274 }
   222 add_filter( 'wp_title', 'twentythirteen_wp_title', 10, 2 );
   275 add_filter( 'wp_title', 'twentythirteen_wp_title', 10, 2 );
   223 
   276 
   225  * Register two widget areas.
   278  * Register two widget areas.
   226  *
   279  *
   227  * @since Twenty Thirteen 1.0
   280  * @since Twenty Thirteen 1.0
   228  */
   281  */
   229 function twentythirteen_widgets_init() {
   282 function twentythirteen_widgets_init() {
   230 	register_sidebar( array(
   283 	register_sidebar(
   231 		'name'          => __( 'Main Widget Area', 'twentythirteen' ),
   284 		array(
   232 		'id'            => 'sidebar-1',
   285 			'name'          => __( 'Main Widget Area', 'twentythirteen' ),
   233 		'description'   => __( 'Appears in the footer section of the site.', 'twentythirteen' ),
   286 			'id'            => 'sidebar-1',
   234 		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
   287 			'description'   => __( 'Appears in the footer section of the site.', 'twentythirteen' ),
   235 		'after_widget'  => '</aside>',
   288 			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
   236 		'before_title'  => '<h3 class="widget-title">',
   289 			'after_widget'  => '</aside>',
   237 		'after_title'   => '</h3>',
   290 			'before_title'  => '<h3 class="widget-title">',
   238 	) );
   291 			'after_title'   => '</h3>',
   239 
   292 		)
   240 	register_sidebar( array(
   293 	);
   241 		'name'          => __( 'Secondary Widget Area', 'twentythirteen' ),
   294 
   242 		'id'            => 'sidebar-2',
   295 	register_sidebar(
   243 		'description'   => __( 'Appears on posts and pages in the sidebar.', 'twentythirteen' ),
   296 		array(
   244 		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
   297 			'name'          => __( 'Secondary Widget Area', 'twentythirteen' ),
   245 		'after_widget'  => '</aside>',
   298 			'id'            => 'sidebar-2',
   246 		'before_title'  => '<h3 class="widget-title">',
   299 			'description'   => __( 'Appears on posts and pages in the sidebar.', 'twentythirteen' ),
   247 		'after_title'   => '</h3>',
   300 			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
   248 	) );
   301 			'after_widget'  => '</aside>',
       
   302 			'before_title'  => '<h3 class="widget-title">',
       
   303 			'after_title'   => '</h3>',
       
   304 		)
       
   305 	);
   249 }
   306 }
   250 add_action( 'widgets_init', 'twentythirteen_widgets_init' );
   307 add_action( 'widgets_init', 'twentythirteen_widgets_init' );
   251 
   308 
   252 if ( ! function_exists( 'twentythirteen_paging_nav' ) ) :
   309 if ( ! function_exists( 'twentythirteen_paging_nav' ) ) :
   253 /**
   310 	/**
   254  * Display navigation to next/previous set of posts when applicable.
   311 	 * Display navigation to next/previous set of posts when applicable.
   255  *
   312 	 *
   256  * @since Twenty Thirteen 1.0
   313 	 * @since Twenty Thirteen 1.0
   257  */
   314 	 */
   258 function twentythirteen_paging_nav() {
   315 	function twentythirteen_paging_nav() {
   259 	global $wp_query;
   316 		global $wp_query;
   260 
   317 
   261 	// Don't print empty markup if there's only one page.
   318 		// Don't print empty markup if there's only one page.
   262 	if ( $wp_query->max_num_pages < 2 )
   319 		if ( $wp_query->max_num_pages < 2 ) {
   263 		return;
   320 			return;
   264 	?>
   321 		}
   265 	<nav class="navigation paging-navigation" role="navigation">
   322 		?>
       
   323 		<nav class="navigation paging-navigation" role="navigation">
   266 		<h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1>
   324 		<h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1>
   267 		<div class="nav-links">
   325 		<div class="nav-links">
   268 
   326 
   269 			<?php if ( get_next_posts_link() ) : ?>
   327 			<?php if ( get_next_posts_link() ) : ?>
   270 			<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentythirteen' ) ); ?></div>
   328 			<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentythirteen' ) ); ?></div>
   275 			<?php endif; ?>
   333 			<?php endif; ?>
   276 
   334 
   277 		</div><!-- .nav-links -->
   335 		</div><!-- .nav-links -->
   278 	</nav><!-- .navigation -->
   336 	</nav><!-- .navigation -->
   279 	<?php
   337 	<?php
   280 }
   338 	}
   281 endif;
   339 endif;
   282 
   340 
   283 if ( ! function_exists( 'twentythirteen_post_nav' ) ) :
   341 if ( ! function_exists( 'twentythirteen_post_nav' ) ) :
   284 /**
   342 	/**
   285  * Display navigation to next/previous post when applicable.
   343 	 * Display navigation to next/previous post when applicable.
   286 *
   344 	 *
   287 * @since Twenty Thirteen 1.0
   345 	 * @since Twenty Thirteen 1.0
   288 */
   346 	 */
   289 function twentythirteen_post_nav() {
   347 	function twentythirteen_post_nav() {
   290 	global $post;
   348 		global $post;
   291 
   349 
   292 	// Don't print empty markup if there's nowhere to navigate.
   350 		// Don't print empty markup if there's nowhere to navigate.
   293 	$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
   351 		$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
   294 	$next     = get_adjacent_post( false, '', false );
   352 		$next     = get_adjacent_post( false, '', false );
   295 
   353 
   296 	if ( ! $next && ! $previous )
   354 		if ( ! $next && ! $previous ) {
   297 		return;
   355 			return;
   298 	?>
   356 		}
   299 	<nav class="navigation post-navigation" role="navigation">
   357 		?>
       
   358 		<nav class="navigation post-navigation" role="navigation">
   300 		<h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentythirteen' ); ?></h1>
   359 		<h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentythirteen' ); ?></h1>
   301 		<div class="nav-links">
   360 		<div class="nav-links">
   302 
   361 
   303 			<?php previous_post_link( '%link', _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'twentythirteen' ) ); ?>
   362 			<?php previous_post_link( '%link', _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'twentythirteen' ) ); ?>
   304 			<?php next_post_link( '%link', _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', 'twentythirteen' ) ); ?>
   363 			<?php next_post_link( '%link', _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', 'twentythirteen' ) ); ?>
   305 
   364 
   306 		</div><!-- .nav-links -->
   365 		</div><!-- .nav-links -->
   307 	</nav><!-- .navigation -->
   366 	</nav><!-- .navigation -->
   308 	<?php
   367 	<?php
   309 }
   368 	}
   310 endif;
   369 endif;
   311 
   370 
   312 if ( ! function_exists( 'twentythirteen_entry_meta' ) ) :
   371 if ( ! function_exists( 'twentythirteen_entry_meta' ) ) :
   313 /**
   372 	/**
   314  * Print HTML with meta information for current post: categories, tags, permalink, author, and date.
   373 	 * Print HTML with meta information for current post: categories, tags, permalink, author, and date.
   315  *
   374 	 *
   316  * Create your own twentythirteen_entry_meta() to override in a child theme.
   375 	 * Create your own twentythirteen_entry_meta() to override in a child theme.
   317  *
   376 	 *
   318  * @since Twenty Thirteen 1.0
   377 	 * @since Twenty Thirteen 1.0
   319  */
   378 	 */
   320 function twentythirteen_entry_meta() {
   379 	function twentythirteen_entry_meta() {
   321 	if ( is_sticky() && is_home() && ! is_paged() )
   380 		if ( is_sticky() && is_home() && ! is_paged() ) {
   322 		echo '<span class="featured-post">' . esc_html__( 'Sticky', 'twentythirteen' ) . '</span>';
   381 			echo '<span class="featured-post">' . esc_html__( 'Sticky', 'twentythirteen' ) . '</span>';
   323 
   382 		}
   324 	if ( ! has_post_format( 'link' ) && 'post' == get_post_type() )
   383 
   325 		twentythirteen_entry_date();
   384 		if ( ! has_post_format( 'link' ) && 'post' == get_post_type() ) {
   326 
   385 			twentythirteen_entry_date();
   327 	// Translators: used between list items, there is a space after the comma.
   386 		}
   328 	$categories_list = get_the_category_list( __( ', ', 'twentythirteen' ) );
   387 
   329 	if ( $categories_list ) {
   388 		// Translators: used between list items, there is a space after the comma.
   330 		echo '<span class="categories-links">' . $categories_list . '</span>';
   389 		$categories_list = get_the_category_list( __( ', ', 'twentythirteen' ) );
   331 	}
   390 		if ( $categories_list ) {
   332 
   391 			echo '<span class="categories-links">' . $categories_list . '</span>';
   333 	// Translators: used between list items, there is a space after the comma.
   392 		}
   334 	$tag_list = get_the_tag_list( '', __( ', ', 'twentythirteen' ) );
   393 
   335 	if ( $tag_list ) {
   394 		// Translators: used between list items, there is a space after the comma.
   336 		echo '<span class="tags-links">' . $tag_list . '</span>';
   395 		$tag_list = get_the_tag_list( '', __( ', ', 'twentythirteen' ) );
   337 	}
   396 		if ( $tag_list ) {
   338 
   397 			echo '<span class="tags-links">' . $tag_list . '</span>';
   339 	// Post author
   398 		}
   340 	if ( 'post' == get_post_type() ) {
   399 
   341 		printf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
   400 		// Post author
   342 			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
   401 		if ( 'post' == get_post_type() ) {
   343 			esc_attr( sprintf( __( 'View all posts by %s', 'twentythirteen' ), get_the_author() ) ),
   402 			printf(
   344 			get_the_author()
   403 				'<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
       
   404 				esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
       
   405 				esc_attr( sprintf( __( 'View all posts by %s', 'twentythirteen' ), get_the_author() ) ),
       
   406 				get_the_author()
       
   407 			);
       
   408 		}
       
   409 	}
       
   410 endif;
       
   411 
       
   412 if ( ! function_exists( 'twentythirteen_entry_date' ) ) :
       
   413 	/**
       
   414 	 * Print HTML with date information for current post.
       
   415 	 *
       
   416 	 * Create your own twentythirteen_entry_date() to override in a child theme.
       
   417 	 *
       
   418 	 * @since Twenty Thirteen 1.0
       
   419 	 *
       
   420 	 * @param boolean $echo (optional) Whether to echo the date. Default true.
       
   421 	 * @return string The HTML-formatted post date.
       
   422 	 */
       
   423 	function twentythirteen_entry_date( $echo = true ) {
       
   424 		if ( has_post_format( array( 'chat', 'status' ) ) ) {
       
   425 			$format_prefix = _x( '%1$s on %2$s', '1: post format name. 2: date', 'twentythirteen' );
       
   426 		} else {
       
   427 			$format_prefix = '%2$s';
       
   428 		}
       
   429 
       
   430 		$date = sprintf(
       
   431 			'<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a></span>',
       
   432 			esc_url( get_permalink() ),
       
   433 			esc_attr( sprintf( __( 'Permalink to %s', 'twentythirteen' ), the_title_attribute( 'echo=0' ) ) ),
       
   434 			esc_attr( get_the_date( 'c' ) ),
       
   435 			esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) )
   345 		);
   436 		);
   346 	}
   437 
   347 }
   438 		if ( $echo ) {
       
   439 			echo $date;
       
   440 		}
       
   441 
       
   442 		return $date;
       
   443 	}
   348 endif;
   444 endif;
   349 
   445 
   350 if ( ! function_exists( 'twentythirteen_entry_date' ) ) :
       
   351 /**
       
   352  * Print HTML with date information for current post.
       
   353  *
       
   354  * Create your own twentythirteen_entry_date() to override in a child theme.
       
   355  *
       
   356  * @since Twenty Thirteen 1.0
       
   357  *
       
   358  * @param boolean $echo (optional) Whether to echo the date. Default true.
       
   359  * @return string The HTML-formatted post date.
       
   360  */
       
   361 function twentythirteen_entry_date( $echo = true ) {
       
   362 	if ( has_post_format( array( 'chat', 'status' ) ) )
       
   363 		$format_prefix = _x( '%1$s on %2$s', '1: post format name. 2: date', 'twentythirteen' );
       
   364 	else
       
   365 		$format_prefix = '%2$s';
       
   366 
       
   367 	$date = sprintf( '<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a></span>',
       
   368 		esc_url( get_permalink() ),
       
   369 		esc_attr( sprintf( __( 'Permalink to %s', 'twentythirteen' ), the_title_attribute( 'echo=0' ) ) ),
       
   370 		esc_attr( get_the_date( 'c' ) ),
       
   371 		esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) )
       
   372 	);
       
   373 
       
   374 	if ( $echo )
       
   375 		echo $date;
       
   376 
       
   377 	return $date;
       
   378 }
       
   379 endif;
       
   380 
       
   381 if ( ! function_exists( 'twentythirteen_the_attached_image' ) ) :
   446 if ( ! function_exists( 'twentythirteen_the_attached_image' ) ) :
   382 /**
       
   383  * Print the attached image with a link to the next attached image.
       
   384  *
       
   385  * @since Twenty Thirteen 1.0
       
   386  */
       
   387 function twentythirteen_the_attached_image() {
       
   388 	/**
   447 	/**
   389 	 * Filter the image attachment size to use.
   448 	 * Print the attached image with a link to the next attached image.
   390 	 *
   449 	 *
   391 	 * @since Twenty thirteen 1.0
   450 	 * @since Twenty Thirteen 1.0
   392 	 *
   451 	 */
   393 	 * @param array $size {
   452 	function twentythirteen_the_attached_image() {
   394 	 *     @type int The attachment height in pixels.
   453 		/**
   395 	 *     @type int The attachment width in pixels.
   454 		 * Filter the image attachment size to use.
   396 	 * }
   455 		 *
   397 	 */
   456 		 * @since Twenty thirteen 1.0
   398 	$attachment_size     = apply_filters( 'twentythirteen_attachment_size', array( 724, 724 ) );
   457 		 *
   399 	$next_attachment_url = wp_get_attachment_url();
   458 		 * @param array $size {
   400 	$post                = get_post();
   459 		 *     @type int The attachment height in pixels.
   401 
   460 		 *     @type int The attachment width in pixels.
   402 	/*
   461 		 * }
   403 	 * Grab the IDs of all the image attachments in a gallery so we can get the URL
   462 		 */
   404 	 * of the next adjacent image in a gallery, or the first image (if we're
   463 		$attachment_size     = apply_filters( 'twentythirteen_attachment_size', array( 724, 724 ) );
   405 	 * looking at the last image in a gallery), or, in a gallery of one, just the
   464 		$next_attachment_url = wp_get_attachment_url();
   406 	 * link to that image file.
   465 		$post                = get_post();
   407 	 */
   466 
   408 	$attachment_ids = get_posts( array(
   467 		/*
   409 		'post_parent'    => $post->post_parent,
   468 		 * Grab the IDs of all the image attachments in a gallery so we can get the URL
   410 		'fields'         => 'ids',
   469 		 * of the next adjacent image in a gallery, or the first image (if we're
   411 		'numberposts'    => -1,
   470 		 * looking at the last image in a gallery), or, in a gallery of one, just the
   412 		'post_status'    => 'inherit',
   471 		 * link to that image file.
   413 		'post_type'      => 'attachment',
   472 		 */
   414 		'post_mime_type' => 'image',
   473 		$attachment_ids = get_posts(
   415 		'order'          => 'ASC',
   474 			array(
   416 		'orderby'        => 'menu_order ID',
   475 				'post_parent'    => $post->post_parent,
   417 	) );
   476 				'fields'         => 'ids',
   418 
   477 				'numberposts'    => -1,
   419 	// If there is more than 1 attachment in a gallery...
   478 				'post_status'    => 'inherit',
   420 	if ( count( $attachment_ids ) > 1 ) {
   479 				'post_type'      => 'attachment',
   421 		foreach ( $attachment_ids as $attachment_id ) {
   480 				'post_mime_type' => 'image',
   422 			if ( $attachment_id == $post->ID ) {
   481 				'order'          => 'ASC',
   423 				$next_id = current( $attachment_ids );
   482 				'orderby'        => 'menu_order ID',
   424 				break;
   483 			)
       
   484 		);
       
   485 
       
   486 		// If there is more than 1 attachment in a gallery...
       
   487 		if ( count( $attachment_ids ) > 1 ) {
       
   488 			foreach ( $attachment_ids as $idx => $attachment_id ) {
       
   489 				if ( $attachment_id == $post->ID ) {
       
   490 					$next_id = $attachment_ids[ ( $idx + 1 ) % count( $attachment_ids ) ];
       
   491 					break;
       
   492 				}
   425 			}
   493 			}
   426 		}
   494 
   427 
   495 			// get the URL of the next image attachment...
   428 		// get the URL of the next image attachment...
   496 			if ( $next_id ) {
   429 		if ( $next_id )
   497 				$next_attachment_url = get_attachment_link( $next_id );
   430 			$next_attachment_url = get_attachment_link( $next_id );
   498 			} // or get the URL of the first image attachment.
   431 
   499 			else {
   432 		// or get the URL of the first image attachment.
   500 				$next_attachment_url = get_attachment_link( reset( $attachment_ids ) );
   433 		else
   501 			}
   434 			$next_attachment_url = get_attachment_link( reset( $attachment_ids ) );
   502 		}
   435 	}
   503 
   436 
   504 		printf(
   437 	printf( '<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>',
   505 			'<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>',
   438 		esc_url( $next_attachment_url ),
   506 			esc_url( $next_attachment_url ),
   439 		the_title_attribute( array( 'echo' => false ) ),
   507 			the_title_attribute( array( 'echo' => false ) ),
   440 		wp_get_attachment_image( $post->ID, $attachment_size )
   508 			wp_get_attachment_image( $post->ID, $attachment_size )
   441 	);
   509 		);
   442 }
   510 	}
   443 endif;
   511 endif;
   444 
   512 
   445 /**
   513 /**
   446  * Return the post URL.
   514  * Return the post URL.
   447  *
   515  *
   460 
   528 
   461 	return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
   529 	return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
   462 }
   530 }
   463 
   531 
   464 if ( ! function_exists( 'twentythirteen_excerpt_more' ) && ! is_admin() ) :
   532 if ( ! function_exists( 'twentythirteen_excerpt_more' ) && ! is_admin() ) :
   465 /**
   533 	/**
   466  * Replaces "[...]" (appended to automatically generated excerpts) with ...
   534 	 * Replaces "[...]" (appended to automatically generated excerpts) with ...
   467  * and a Continue reading link.
   535 	 * and a Continue reading link.
   468  *
   536 	 *
   469  * @since Twenty Thirteen 1.4
   537 	 * @since Twenty Thirteen 1.4
   470  *
   538 	 *
   471  * @param string $more Default Read More excerpt link.
   539 	 * @param string $more Default Read More excerpt link.
   472  * @return string Filtered Read More excerpt link.
   540 	 * @return string Filtered Read More excerpt link.
   473  */
   541 	 */
   474 function twentythirteen_excerpt_more( $more ) {
   542 	function twentythirteen_excerpt_more( $more ) {
   475 	$link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
   543 		$link = sprintf(
   476 		esc_url( get_permalink( get_the_ID() ) ),
   544 			'<a href="%1$s" class="more-link">%2$s</a>',
       
   545 			esc_url( get_permalink( get_the_ID() ) ),
   477 			/* translators: %s: Name of current post */
   546 			/* translators: %s: Name of current post */
   478 			sprintf( __( 'Continue reading %s <span class="meta-nav">&rarr;</span>', 'twentythirteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
   547 			sprintf( __( 'Continue reading %s <span class="meta-nav">&rarr;</span>', 'twentythirteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
   479 		);
   548 		);
   480 	return ' &hellip; ' . $link;
   549 		return ' &hellip; ' . $link;
   481 }
   550 	}
   482 add_filter( 'excerpt_more', 'twentythirteen_excerpt_more' );
   551 	add_filter( 'excerpt_more', 'twentythirteen_excerpt_more' );
   483 endif;
   552 endif;
   484 
   553 
   485 /**
   554 /**
   486  * Extend the default WordPress body classes.
   555  * Extend the default WordPress body classes.
   487  *
   556  *
   494  *
   563  *
   495  * @param array $classes A list of existing body class values.
   564  * @param array $classes A list of existing body class values.
   496  * @return array The filtered body class list.
   565  * @return array The filtered body class list.
   497  */
   566  */
   498 function twentythirteen_body_class( $classes ) {
   567 function twentythirteen_body_class( $classes ) {
   499 	if ( ! is_multi_author() )
   568 	if ( ! is_multi_author() ) {
   500 		$classes[] = 'single-author';
   569 		$classes[] = 'single-author';
   501 
   570 	}
   502 	if ( is_active_sidebar( 'sidebar-2' ) && ! is_attachment() && ! is_404() )
   571 
       
   572 	if ( is_active_sidebar( 'sidebar-2' ) && ! is_attachment() && ! is_404() ) {
   503 		$classes[] = 'sidebar';
   573 		$classes[] = 'sidebar';
   504 
   574 	}
   505 	if ( ! get_option( 'show_avatars' ) )
   575 
       
   576 	if ( ! get_option( 'show_avatars' ) ) {
   506 		$classes[] = 'no-avatars';
   577 		$classes[] = 'no-avatars';
       
   578 	}
   507 
   579 
   508 	return $classes;
   580 	return $classes;
   509 }
   581 }
   510 add_filter( 'body_class', 'twentythirteen_body_class' );
   582 add_filter( 'body_class', 'twentythirteen_body_class' );
   511 
   583 
   515  * @since Twenty Thirteen 1.0
   587  * @since Twenty Thirteen 1.0
   516  */
   588  */
   517 function twentythirteen_content_width() {
   589 function twentythirteen_content_width() {
   518 	global $content_width;
   590 	global $content_width;
   519 
   591 
   520 	if ( is_attachment() )
   592 	if ( is_attachment() ) {
   521 		$content_width = 724;
   593 		$content_width = 724;
   522 	elseif ( has_post_format( 'audio' ) )
   594 	} elseif ( has_post_format( 'audio' ) ) {
   523 		$content_width = 484;
   595 		$content_width = 484;
       
   596 	}
   524 }
   597 }
   525 add_action( 'template_redirect', 'twentythirteen_content_width' );
   598 add_action( 'template_redirect', 'twentythirteen_content_width' );
   526 
   599 
   527 /**
   600 /**
   528  * Add postMessage support for site title and description for the Customizer.
   601  * Add postMessage support for site title and description for the Customizer.
   533  */
   606  */
   534 function twentythirteen_customize_register( $wp_customize ) {
   607 function twentythirteen_customize_register( $wp_customize ) {
   535 	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
   608 	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
   536 	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
   609 	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
   537 	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
   610 	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
       
   611 
       
   612 	if ( isset( $wp_customize->selective_refresh ) ) {
       
   613 		$wp_customize->selective_refresh->add_partial(
       
   614 			'blogname', array(
       
   615 				'selector'            => '.site-title',
       
   616 				'container_inclusive' => false,
       
   617 				'render_callback'     => 'twentythirteen_customize_partial_blogname',
       
   618 			)
       
   619 		);
       
   620 		$wp_customize->selective_refresh->add_partial(
       
   621 			'blogdescription', array(
       
   622 				'selector'            => '.site-description',
       
   623 				'container_inclusive' => false,
       
   624 				'render_callback'     => 'twentythirteen_customize_partial_blogdescription',
       
   625 			)
       
   626 		);
       
   627 	}
   538 }
   628 }
   539 add_action( 'customize_register', 'twentythirteen_customize_register' );
   629 add_action( 'customize_register', 'twentythirteen_customize_register' );
       
   630 
       
   631 /**
       
   632  * Render the site title for the selective refresh partial.
       
   633  *
       
   634  * @since Twenty Thirteen 1.9
       
   635  * @see twentythirteen_customize_register()
       
   636  *
       
   637  * @return void
       
   638  */
       
   639 function twentythirteen_customize_partial_blogname() {
       
   640 	bloginfo( 'name' );
       
   641 }
       
   642 
       
   643 /**
       
   644  * Render the site tagline for the selective refresh partial.
       
   645  *
       
   646  * @since Twenty Thirteen 1.9
       
   647  * @see twentythirteen_customize_register()
       
   648  *
       
   649  * @return void
       
   650  */
       
   651 function twentythirteen_customize_partial_blogdescription() {
       
   652 	bloginfo( 'description' );
       
   653 }
   540 
   654 
   541 /**
   655 /**
   542  * Enqueue Javascript postMessage handlers for the Customizer.
   656  * Enqueue Javascript postMessage handlers for the Customizer.
   543  *
   657  *
   544  * Binds JavaScript handlers to make the Customizer preview
   658  * Binds JavaScript handlers to make the Customizer preview
   548  */
   662  */
   549 function twentythirteen_customize_preview_js() {
   663 function twentythirteen_customize_preview_js() {
   550 	wp_enqueue_script( 'twentythirteen-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20141120', true );
   664 	wp_enqueue_script( 'twentythirteen-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20141120', true );
   551 }
   665 }
   552 add_action( 'customize_preview_init', 'twentythirteen_customize_preview_js' );
   666 add_action( 'customize_preview_init', 'twentythirteen_customize_preview_js' );
       
   667 
       
   668 /**
       
   669  * Modifies tag cloud widget arguments to display all tags in the same font size
       
   670  * and use list format for better accessibility.
       
   671  *
       
   672  * @since Twenty Thirteen 2.3
       
   673  *
       
   674  * @param array $args Arguments for tag cloud widget.
       
   675  * @return array The filtered arguments for tag cloud widget.
       
   676  */
       
   677 function twentythirteen_widget_tag_cloud_args( $args ) {
       
   678 	$args['largest']  = 22;
       
   679 	$args['smallest'] = 8;
       
   680 	$args['unit']     = 'pt';
       
   681 	$args['format']   = 'list';
       
   682 
       
   683 	return $args;
       
   684 }
       
   685 add_filter( 'widget_tag_cloud_args', 'twentythirteen_widget_tag_cloud_args' );