wp/wp-content/themes/twentytwelve/functions.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
     4  *
     4  *
     5  * Sets up the theme and provides some helper functions, which are used
     5  * Sets up the theme and provides some helper functions, which are used
     6  * in the theme as custom template tags. Others are attached to action and
     6  * in the theme as custom template tags. Others are attached to action and
     7  * filter hooks in WordPress to change core functionality.
     7  * filter hooks in WordPress to change core functionality.
     8  *
     8  *
     9  * When using a child theme (see http://codex.wordpress.org/Theme_Development and
     9  * When using a child theme (see https://codex.wordpress.org/Theme_Development and
    10  * http://codex.wordpress.org/Child_Themes), you can override certain functions
    10  * https://codex.wordpress.org/Child_Themes), you can override certain functions
    11  * (those wrapped in a function_exists() call) by defining them first in your child theme's
    11  * (those wrapped in a function_exists() call) by defining them first in your child theme's
    12  * functions.php file. The child theme's functions.php file is included before the parent
    12  * functions.php file. The child theme's functions.php file is included before the parent
    13  * theme's file, so the child theme functions would be used.
    13  * theme's file, so the child theme functions would be used.
    14  *
    14  *
    15  * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
    15  * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
    16  * to a filter or action hook.
    16  * to a filter or action hook.
    17  *
    17  *
    18  * For more information on hooks, actions, and filters, @link http://codex.wordpress.org/Plugin_API
    18  * For more information on hooks, actions, and filters, @link https://codex.wordpress.org/Plugin_API
    19  *
    19  *
    20  * @package WordPress
    20  * @package WordPress
    21  * @subpackage Twenty_Twelve
    21  * @subpackage Twenty_Twelve
    22  * @since Twenty Twelve 1.0
    22  * @since Twenty Twelve 1.0
    23  */
    23  */
   126 
   126 
   127 /**
   127 /**
   128  * Enqueue scripts and styles for front-end.
   128  * Enqueue scripts and styles for front-end.
   129  *
   129  *
   130  * @since Twenty Twelve 1.0
   130  * @since Twenty Twelve 1.0
   131  *
       
   132  * @return void
       
   133  */
   131  */
   134 function twentytwelve_scripts_styles() {
   132 function twentytwelve_scripts_styles() {
   135 	global $wp_styles;
   133 	global $wp_styles;
   136 
   134 
   137 	/*
   135 	/*
   140 	 */
   138 	 */
   141 	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
   139 	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
   142 		wp_enqueue_script( 'comment-reply' );
   140 		wp_enqueue_script( 'comment-reply' );
   143 
   141 
   144 	// Adds JavaScript for handling the navigation menu hide-and-show behavior.
   142 	// Adds JavaScript for handling the navigation menu hide-and-show behavior.
   145 	wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '1.0', true );
   143 	wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20140711', true );
   146 
   144 
   147 	$font_url = twentytwelve_get_font_url();
   145 	$font_url = twentytwelve_get_font_url();
   148 	if ( ! empty( $font_url ) )
   146 	if ( ! empty( $font_url ) )
   149 		wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
   147 		wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
   150 
   148 
   201 
   199 
   202 	if ( is_feed() )
   200 	if ( is_feed() )
   203 		return $title;
   201 		return $title;
   204 
   202 
   205 	// Add the site name.
   203 	// Add the site name.
   206 	$title .= get_bloginfo( 'name' );
   204 	$title .= get_bloginfo( 'name', 'display' );
   207 
   205 
   208 	// Add the site description for the home/front page.
   206 	// Add the site description for the home/front page.
   209 	$site_description = get_bloginfo( 'description', 'display' );
   207 	$site_description = get_bloginfo( 'description', 'display' );
   210 	if ( $site_description && ( is_home() || is_front_page() ) )
   208 	if ( $site_description && ( is_home() || is_front_page() ) )
   211 		$title = "$title $sep $site_description";
   209 		$title = "$title $sep $site_description";
   212 
   210 
   213 	// Add a page number if necessary.
   211 	// Add a page number if necessary.
   214 	if ( $paged >= 2 || $page >= 2 )
   212 	if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() )
   215 		$title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );
   213 		$title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );
   216 
   214 
   217 	return $title;
   215 	return $title;
   218 }
   216 }
   219 add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );
   217 add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );
   279  * @since Twenty Twelve 1.0
   277  * @since Twenty Twelve 1.0
   280  */
   278  */
   281 function twentytwelve_content_nav( $html_id ) {
   279 function twentytwelve_content_nav( $html_id ) {
   282 	global $wp_query;
   280 	global $wp_query;
   283 
   281 
   284 	$html_id = esc_attr( $html_id );
       
   285 
       
   286 	if ( $wp_query->max_num_pages > 1 ) : ?>
   282 	if ( $wp_query->max_num_pages > 1 ) : ?>
   287 		<nav id="<?php echo $html_id; ?>" class="navigation" role="navigation">
   283 		<nav id="<?php echo esc_attr( $html_id ); ?>" class="navigation" role="navigation">
   288 			<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
   284 			<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
   289 			<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
   285 			<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
   290 			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
   286 			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
   291 		</nav><!-- #<?php echo $html_id; ?> .navigation -->
   287 		</nav><!-- .navigation -->
   292 	<?php endif;
   288 	<?php endif;
   293 }
   289 }
   294 endif;
   290 endif;
   295 
   291 
   296 if ( ! function_exists( 'twentytwelve_comment' ) ) :
   292 if ( ! function_exists( 'twentytwelve_comment' ) ) :
   301  * simply create your own twentytwelve_comment(), and that function will be used instead.
   297  * simply create your own twentytwelve_comment(), and that function will be used instead.
   302  *
   298  *
   303  * Used as a callback by wp_list_comments() for displaying the comments.
   299  * Used as a callback by wp_list_comments() for displaying the comments.
   304  *
   300  *
   305  * @since Twenty Twelve 1.0
   301  * @since Twenty Twelve 1.0
   306  *
       
   307  * @return void
       
   308  */
   302  */
   309 function twentytwelve_comment( $comment, $args, $depth ) {
   303 function twentytwelve_comment( $comment, $args, $depth ) {
   310 	$GLOBALS['comment'] = $comment;
   304 	$GLOBALS['comment'] = $comment;
   311 	switch ( $comment->comment_type ) :
   305 	switch ( $comment->comment_type ) :
   312 		case 'pingback' :
   306 		case 'pingback' :
   366  * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
   360  * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
   367  *
   361  *
   368  * Create your own twentytwelve_entry_meta() to override in a child theme.
   362  * Create your own twentytwelve_entry_meta() to override in a child theme.
   369  *
   363  *
   370  * @since Twenty Twelve 1.0
   364  * @since Twenty Twelve 1.0
   371  *
       
   372  * @return void
       
   373  */
   365  */
   374 function twentytwelve_entry_meta() {
   366 function twentytwelve_entry_meta() {
   375 	// Translators: used between list items, there is a space after the comma.
   367 	// Translators: used between list items, there is a space after the comma.
   376 	$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
   368 	$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
   377 
   369 
   465  *
   457  *
   466  * Adjusts content_width value for full-width and single image attachment
   458  * Adjusts content_width value for full-width and single image attachment
   467  * templates, and when there are no active widgets in the sidebar.
   459  * templates, and when there are no active widgets in the sidebar.
   468  *
   460  *
   469  * @since Twenty Twelve 1.0
   461  * @since Twenty Twelve 1.0
   470  *
       
   471  * @return void
       
   472  */
   462  */
   473 function twentytwelve_content_width() {
   463 function twentytwelve_content_width() {
   474 	if ( is_page_template( 'page-templates/full-width.php' ) || is_attachment() || ! is_active_sidebar( 'sidebar-1' ) ) {
   464 	if ( is_page_template( 'page-templates/full-width.php' ) || is_attachment() || ! is_active_sidebar( 'sidebar-1' ) ) {
   475 		global $content_width;
   465 		global $content_width;
   476 		$content_width = 960;
   466 		$content_width = 960;
   484  * Add postMessage support for site title and description for the Customizer.
   474  * Add postMessage support for site title and description for the Customizer.
   485  *
   475  *
   486  * @since Twenty Twelve 1.0
   476  * @since Twenty Twelve 1.0
   487  *
   477  *
   488  * @param WP_Customize_Manager $wp_customize Customizer object.
   478  * @param WP_Customize_Manager $wp_customize Customizer object.
   489  * @return void
       
   490  */
   479  */
   491 function twentytwelve_customize_register( $wp_customize ) {
   480 function twentytwelve_customize_register( $wp_customize ) {
   492 	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
   481 	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
   493 	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
   482 	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
   494 	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
   483 	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
   499  * Enqueue Javascript postMessage handlers for the Customizer.
   488  * Enqueue Javascript postMessage handlers for the Customizer.
   500  *
   489  *
   501  * Binds JS handlers to make the Customizer preview reload changes asynchronously.
   490  * Binds JS handlers to make the Customizer preview reload changes asynchronously.
   502  *
   491  *
   503  * @since Twenty Twelve 1.0
   492  * @since Twenty Twelve 1.0
   504  *
       
   505  * @return void
       
   506  */
   493  */
   507 function twentytwelve_customize_preview_js() {
   494 function twentytwelve_customize_preview_js() {
   508 	wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20130301', true );
   495 	wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20141120', true );
   509 }
   496 }
   510 add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' );
   497 add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' );