[ Index ] |
WordPress Cross Reference |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Twenty Fourteen functions and definitions 4 * 5 * Set up the theme and provides some helper functions, which are used in the 6 * theme as custom template tags. Others are attached to action and filter 7 * hooks in WordPress to change core functionality. 8 * 9 * When using a child theme you can override certain functions (those wrapped 10 * in a function_exists() call) by defining them first in your child theme's 11 * functions.php file. The child theme's functions.php file is included before 12 * the parent theme's file, so the child theme functions would be used. 13 * 14 * @link http://codex.wordpress.org/Theme_Development 15 * @link http://codex.wordpress.org/Child_Themes 16 * 17 * Functions that are not pluggable (not wrapped in function_exists()) are 18 * instead attached to a filter or action hook. 19 * 20 * For more information on hooks, actions, and filters, 21 * @link http://codex.wordpress.org/Plugin_API 22 * 23 * @package WordPress 24 * @subpackage Twenty_Fourteen 25 * @since Twenty Fourteen 1.0 26 */ 27 28 /** 29 * Set up the content width value based on the theme's design. 30 * 31 * @see twentyfourteen_content_width() 32 * 33 * @since Twenty Fourteen 1.0 34 */ 35 if ( ! isset( $content_width ) ) { 36 $content_width = 474; 37 } 38 39 /** 40 * Twenty Fourteen only works in WordPress 3.6 or later. 41 */ 42 if ( version_compare( $GLOBALS['wp_version'], '3.6', '<' ) ) { 43 require get_template_directory() . '/inc/back-compat.php'; 44 } 45 46 if ( ! function_exists( 'twentyfourteen_setup' ) ) : 47 /** 48 * Twenty Fourteen setup. 49 * 50 * Set up theme defaults and registers support for various WordPress features. 51 * 52 * Note that this function is hooked into the after_setup_theme hook, which 53 * runs before the init hook. The init hook is too late for some features, such 54 * as indicating support post thumbnails. 55 * 56 * @since Twenty Fourteen 1.0 57 */ 58 function twentyfourteen_setup() { 59 60 /* 61 * Make Twenty Fourteen available for translation. 62 * 63 * Translations can be added to the /languages/ directory. 64 * If you're building a theme based on Twenty Fourteen, use a find and 65 * replace to change 'twentyfourteen' to the name of your theme in all 66 * template files. 67 */ 68 load_theme_textdomain( 'twentyfourteen', get_template_directory() . '/languages' ); 69 70 // This theme styles the visual editor to resemble the theme style. 71 add_editor_style( array( 'css/editor-style.css', twentyfourteen_font_url() ) ); 72 73 // Add RSS feed links to <head> for posts and comments. 74 add_theme_support( 'automatic-feed-links' ); 75 76 // Enable support for Post Thumbnails, and declare two sizes. 77 add_theme_support( 'post-thumbnails' ); 78 set_post_thumbnail_size( 672, 372, true ); 79 add_image_size( 'twentyfourteen-full-width', 1038, 576, true ); 80 81 // This theme uses wp_nav_menu() in two locations. 82 register_nav_menus( array( 83 'primary' => __( 'Top primary menu', 'twentyfourteen' ), 84 'secondary' => __( 'Secondary menu in left sidebar', 'twentyfourteen' ), 85 ) ); 86 87 /* 88 * Switch default core markup for search form, comment form, and comments 89 * to output valid HTML5. 90 */ 91 add_theme_support( 'html5', array( 92 'search-form', 'comment-form', 'comment-list', 93 ) ); 94 95 /* 96 * Enable support for Post Formats. 97 * See http://codex.wordpress.org/Post_Formats 98 */ 99 add_theme_support( 'post-formats', array( 100 'aside', 'image', 'video', 'audio', 'quote', 'link', 'gallery', 101 ) ); 102 103 // This theme allows users to set a custom background. 104 add_theme_support( 'custom-background', apply_filters( 'twentyfourteen_custom_background_args', array( 105 'default-color' => 'f5f5f5', 106 ) ) ); 107 108 // Add support for featured content. 109 add_theme_support( 'featured-content', array( 110 'featured_content_filter' => 'twentyfourteen_get_featured_posts', 111 'max_posts' => 6, 112 ) ); 113 114 // This theme uses its own gallery styles. 115 add_filter( 'use_default_gallery_style', '__return_false' ); 116 } 117 endif; // twentyfourteen_setup 118 add_action( 'after_setup_theme', 'twentyfourteen_setup' ); 119 120 /** 121 * Adjust content_width value for image attachment template. 122 * 123 * @since Twenty Fourteen 1.0 124 * 125 * @return void 126 */ 127 function twentyfourteen_content_width() { 128 if ( is_attachment() && wp_attachment_is_image() ) { 129 $GLOBALS['content_width'] = 810; 130 } 131 } 132 add_action( 'template_redirect', 'twentyfourteen_content_width' ); 133 134 /** 135 * Getter function for Featured Content Plugin. 136 * 137 * @since Twenty Fourteen 1.0 138 * 139 * @return array An array of WP_Post objects. 140 */ 141 function twentyfourteen_get_featured_posts() { 142 /** 143 * Filter the featured posts to return in Twenty Fourteen. 144 * 145 * @since Twenty Fourteen 1.0 146 * 147 * @param array|bool $posts Array of featured posts, otherwise false. 148 */ 149 return apply_filters( 'twentyfourteen_get_featured_posts', array() ); 150 } 151 152 /** 153 * A helper conditional function that returns a boolean value. 154 * 155 * @since Twenty Fourteen 1.0 156 * 157 * @return bool Whether there are featured posts. 158 */ 159 function twentyfourteen_has_featured_posts() { 160 return ! is_paged() && (bool) twentyfourteen_get_featured_posts(); 161 } 162 163 /** 164 * Register three Twenty Fourteen widget areas. 165 * 166 * @since Twenty Fourteen 1.0 167 * 168 * @return void 169 */ 170 function twentyfourteen_widgets_init() { 171 require get_template_directory() . '/inc/widgets.php'; 172 register_widget( 'Twenty_Fourteen_Ephemera_Widget' ); 173 174 register_sidebar( array( 175 'name' => __( 'Primary Sidebar', 'twentyfourteen' ), 176 'id' => 'sidebar-1', 177 'description' => __( 'Main sidebar that appears on the left.', 'twentyfourteen' ), 178 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 179 'after_widget' => '</aside>', 180 'before_title' => '<h1 class="widget-title">', 181 'after_title' => '</h1>', 182 ) ); 183 register_sidebar( array( 184 'name' => __( 'Content Sidebar', 'twentyfourteen' ), 185 'id' => 'sidebar-2', 186 'description' => __( 'Additional sidebar that appears on the right.', 'twentyfourteen' ), 187 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 188 'after_widget' => '</aside>', 189 'before_title' => '<h1 class="widget-title">', 190 'after_title' => '</h1>', 191 ) ); 192 register_sidebar( array( 193 'name' => __( 'Footer Widget Area', 'twentyfourteen' ), 194 'id' => 'sidebar-3', 195 'description' => __( 'Appears in the footer section of the site.', 'twentyfourteen' ), 196 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 197 'after_widget' => '</aside>', 198 'before_title' => '<h1 class="widget-title">', 199 'after_title' => '</h1>', 200 ) ); 201 } 202 add_action( 'widgets_init', 'twentyfourteen_widgets_init' ); 203 204 /** 205 * Register Lato Google font for Twenty Fourteen. 206 * 207 * @since Twenty Fourteen 1.0 208 * 209 * @return string 210 */ 211 function twentyfourteen_font_url() { 212 $font_url = ''; 213 /* 214 * Translators: If there are characters in your language that are not supported 215 * by Lato, translate this to 'off'. Do not translate into your own language. 216 */ 217 if ( 'off' !== _x( 'on', 'Lato font: on or off', 'twentyfourteen' ) ) { 218 $font_url = add_query_arg( 'family', urlencode( 'Lato:300,400,700,900,300italic,400italic,700italic' ), "//fonts.googleapis.com/css" ); 219 } 220 221 return $font_url; 222 } 223 224 /** 225 * Enqueue scripts and styles for the front end. 226 * 227 * @since Twenty Fourteen 1.0 228 * 229 * @return void 230 */ 231 function twentyfourteen_scripts() { 232 // Add Lato font, used in the main stylesheet. 233 wp_enqueue_style( 'twentyfourteen-lato', twentyfourteen_font_url(), array(), null ); 234 235 // Add Genericons font, used in the main stylesheet. 236 wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.0.2' ); 237 238 // Load our main stylesheet. 239 wp_enqueue_style( 'twentyfourteen-style', get_stylesheet_uri(), array( 'genericons' ) ); 240 241 // Load the Internet Explorer specific stylesheet. 242 wp_enqueue_style( 'twentyfourteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentyfourteen-style', 'genericons' ), '20131205' ); 243 wp_style_add_data( 'twentyfourteen-ie', 'conditional', 'lt IE 9' ); 244 245 if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { 246 wp_enqueue_script( 'comment-reply' ); 247 } 248 249 if ( is_singular() && wp_attachment_is_image() ) { 250 wp_enqueue_script( 'twentyfourteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20130402' ); 251 } 252 253 if ( is_active_sidebar( 'sidebar-3' ) ) { 254 wp_enqueue_script( 'jquery-masonry' ); 255 } 256 257 if ( is_front_page() && 'slider' == get_theme_mod( 'featured_content_layout' ) ) { 258 wp_enqueue_script( 'twentyfourteen-slider', get_template_directory_uri() . '/js/slider.js', array( 'jquery' ), '20131205', true ); 259 wp_localize_script( 'twentyfourteen-slider', 'featuredSliderDefaults', array( 260 'prevText' => __( 'Previous', 'twentyfourteen' ), 261 'nextText' => __( 'Next', 'twentyfourteen' ) 262 ) ); 263 } 264 265 wp_enqueue_script( 'twentyfourteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20131209', true ); 266 } 267 add_action( 'wp_enqueue_scripts', 'twentyfourteen_scripts' ); 268 269 /** 270 * Enqueue Google fonts style to admin screen for custom header display. 271 * 272 * @since Twenty Fourteen 1.0 273 * 274 * @return void 275 */ 276 function twentyfourteen_admin_fonts() { 277 wp_enqueue_style( 'twentyfourteen-lato', twentyfourteen_font_url(), array(), null ); 278 } 279 add_action( 'admin_print_scripts-appearance_page_custom-header', 'twentyfourteen_admin_fonts' ); 280 281 if ( ! function_exists( 'twentyfourteen_the_attached_image' ) ) : 282 /** 283 * Print the attached image with a link to the next attached image. 284 * 285 * @since Twenty Fourteen 1.0 286 * 287 * @return void 288 */ 289 function twentyfourteen_the_attached_image() { 290 $post = get_post(); 291 /** 292 * Filter the default Twenty Fourteen attachment size. 293 * 294 * @since Twenty Fourteen 1.0 295 * 296 * @param array $dimensions { 297 * An array of height and width dimensions. 298 * 299 * @type int $height Height of the image in pixels. Default 810. 300 * @type int $width Width of the image in pixels. Default 810. 301 * } 302 */ 303 $attachment_size = apply_filters( 'twentyfourteen_attachment_size', array( 810, 810 ) ); 304 $next_attachment_url = wp_get_attachment_url(); 305 306 /* 307 * Grab the IDs of all the image attachments in a gallery so we can get the URL 308 * of the next adjacent image in a gallery, or the first image (if we're 309 * looking at the last image in a gallery), or, in a gallery of one, just the 310 * link to that image file. 311 */ 312 $attachment_ids = get_posts( array( 313 'post_parent' => $post->post_parent, 314 'fields' => 'ids', 315 'numberposts' => -1, 316 'post_status' => 'inherit', 317 'post_type' => 'attachment', 318 'post_mime_type' => 'image', 319 'order' => 'ASC', 320 'orderby' => 'menu_order ID', 321 ) ); 322 323 // If there is more than 1 attachment in a gallery... 324 if ( count( $attachment_ids ) > 1 ) { 325 foreach ( $attachment_ids as $attachment_id ) { 326 if ( $attachment_id == $post->ID ) { 327 $next_id = current( $attachment_ids ); 328 break; 329 } 330 } 331 332 // get the URL of the next image attachment... 333 if ( $next_id ) { 334 $next_attachment_url = get_attachment_link( $next_id ); 335 } 336 337 // or get the URL of the first image attachment. 338 else { 339 $next_attachment_url = get_attachment_link( array_shift( $attachment_ids ) ); 340 } 341 } 342 343 printf( '<a href="%1$s" rel="attachment">%2$s</a>', 344 esc_url( $next_attachment_url ), 345 wp_get_attachment_image( $post->ID, $attachment_size ) 346 ); 347 } 348 endif; 349 350 if ( ! function_exists( 'twentyfourteen_list_authors' ) ) : 351 /** 352 * Print a list of all site contributors who published at least one post. 353 * 354 * @since Twenty Fourteen 1.0 355 * 356 * @return void 357 */ 358 function twentyfourteen_list_authors() { 359 $contributor_ids = get_users( array( 360 'fields' => 'ID', 361 'orderby' => 'post_count', 362 'order' => 'DESC', 363 'who' => 'authors', 364 ) ); 365 366 foreach ( $contributor_ids as $contributor_id ) : 367 $post_count = count_user_posts( $contributor_id ); 368 369 // Move on if user has not published a post (yet). 370 if ( ! $post_count ) { 371 continue; 372 } 373 ?> 374 375 <div class="contributor"> 376 <div class="contributor-info"> 377 <div class="contributor-avatar"><?php echo get_avatar( $contributor_id, 132 ); ?></div> 378 <div class="contributor-summary"> 379 <h2 class="contributor-name"><?php echo get_the_author_meta( 'display_name', $contributor_id ); ?></h2> 380 <p class="contributor-bio"> 381 <?php echo get_the_author_meta( 'description', $contributor_id ); ?> 382 </p> 383 <a class="contributor-posts-link" href="<?php echo esc_url( get_author_posts_url( $contributor_id ) ); ?>"> 384 <?php printf( _n( '%d Article', '%d Articles', $post_count, 'twentyfourteen' ), $post_count ); ?> 385 </a> 386 </div><!-- .contributor-summary --> 387 </div><!-- .contributor-info --> 388 </div><!-- .contributor --> 389 390 <?php 391 endforeach; 392 } 393 endif; 394 395 /** 396 * Extend the default WordPress body classes. 397 * 398 * Adds body classes to denote: 399 * 1. Single or multiple authors. 400 * 2. Presence of header image. 401 * 3. Index views. 402 * 4. Full-width content layout. 403 * 5. Presence of footer widgets. 404 * 6. Single views. 405 * 7. Featured content layout. 406 * 407 * @since Twenty Fourteen 1.0 408 * 409 * @param array $classes A list of existing body class values. 410 * @return array The filtered body class list. 411 */ 412 function twentyfourteen_body_classes( $classes ) { 413 if ( is_multi_author() ) { 414 $classes[] = 'group-blog'; 415 } 416 417 if ( get_header_image() ) { 418 $classes[] = 'header-image'; 419 } else { 420 $classes[] = 'masthead-fixed'; 421 } 422 423 if ( is_archive() || is_search() || is_home() ) { 424 $classes[] = 'list-view'; 425 } 426 427 if ( ( ! is_active_sidebar( 'sidebar-2' ) ) 428 || is_page_template( 'page-templates/full-width.php' ) 429 || is_page_template( 'page-templates/contributors.php' ) 430 || is_attachment() ) { 431 $classes[] = 'full-width'; 432 } 433 434 if ( is_active_sidebar( 'sidebar-3' ) ) { 435 $classes[] = 'footer-widgets'; 436 } 437 438 if ( is_singular() && ! is_front_page() ) { 439 $classes[] = 'singular'; 440 } 441 442 if ( is_front_page() && 'slider' == get_theme_mod( 'featured_content_layout' ) ) { 443 $classes[] = 'slider'; 444 } elseif ( is_front_page() ) { 445 $classes[] = 'grid'; 446 } 447 448 return $classes; 449 } 450 add_filter( 'body_class', 'twentyfourteen_body_classes' ); 451 452 /** 453 * Extend the default WordPress post classes. 454 * 455 * Adds a post class to denote: 456 * Non-password protected page with a post thumbnail. 457 * 458 * @since Twenty Fourteen 1.0 459 * 460 * @param array $classes A list of existing post class values. 461 * @return array The filtered post class list. 462 */ 463 function twentyfourteen_post_classes( $classes ) { 464 if ( ! post_password_required() && has_post_thumbnail() ) { 465 $classes[] = 'has-post-thumbnail'; 466 } 467 468 return $classes; 469 } 470 add_filter( 'post_class', 'twentyfourteen_post_classes' ); 471 472 /** 473 * Create a nicely formatted and more specific title element text for output 474 * in head of document, based on current view. 475 * 476 * @since Twenty Fourteen 1.0 477 * 478 * @param string $title Default title text for current view. 479 * @param string $sep Optional separator. 480 * @return string The filtered title. 481 */ 482 function twentyfourteen_wp_title( $title, $sep ) { 483 global $paged, $page; 484 485 if ( is_feed() ) { 486 return $title; 487 } 488 489 // Add the site name. 490 $title .= get_bloginfo( 'name' ); 491 492 // Add the site description for the home/front page. 493 $site_description = get_bloginfo( 'description', 'display' ); 494 if ( $site_description && ( is_home() || is_front_page() ) ) { 495 $title = "$title $sep $site_description"; 496 } 497 498 // Add a page number if necessary. 499 if ( $paged >= 2 || $page >= 2 ) { 500 $title = "$title $sep " . sprintf( __( 'Page %s', 'twentyfourteen' ), max( $paged, $page ) ); 501 } 502 503 return $title; 504 } 505 add_filter( 'wp_title', 'twentyfourteen_wp_title', 10, 2 ); 506 507 // Implement Custom Header features. 508 require get_template_directory() . '/inc/custom-header.php'; 509 510 // Custom template tags for this theme. 511 require get_template_directory() . '/inc/template-tags.php'; 512 513 // Add Theme Customizer functionality. 514 require get_template_directory() . '/inc/customizer.php'; 515 516 /* 517 * Add Featured Content functionality. 518 * 519 * To overwrite in a plugin, define your own Featured_Content class on or 520 * before the 'setup_theme' hook. 521 */ 522 if ( ! class_exists( 'Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] ) { 523 require get_template_directory() . '/inc/featured-content.php'; 524 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 25 01:41:18 2014 | WordPress honlapkészítés: online1.hu |