Changeset 13886 for trunk/wp-content/themes/twentyten/functions.php
- Timestamp:
- 03/30/2010 12:05:17 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-content/themes/twentyten/functions.php
r13885 r13886 3 3 * TwentyTen functions and definitions 4 4 * 5 * Sets up the theme and provides some helper functions used 6 * in other parts of the theme. All functions are pluggable 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, twentyten_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), you can 13 * override certain functions (those wrapped in a function_exists() call) by defining 14 * them first in your child theme's functions.php file. The child theme's functions.php 15 * file is included before the parent theme's file, so the child theme functions would 16 * 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. For example: 21 * 22 * <code> 23 * remove_action( 'after_setup_theme', 'twentyten_setup' ); 24 * add_action( 'after_setup_theme', 'my_child_theme_setup' ); 25 * function my_child_theme_setup() { 26 * ... 27 * } 28 * </code> 29 * 30 * For more information on hooks, see http://codex.wordpress.org/Plugin_API. 7 31 * 8 32 * @package WordPress … … 12 36 13 37 /** 14 * Set the content width based on the Theme CSS. Can be overriden15 * 16 * Used in attachment.php to set the width of images. Should17 * be equal to the width set for .onecolumn #content in style.css38 * Set the content width based on the theme's design and stylesheet. 39 * 40 * Used to set the width of images and content. Should be equal to the width the theme 41 * is designed for, generally via the style.css stylesheet. 18 42 */ 19 43 if ( ! isset( $content_width ) ) 20 44 $content_width = 640; 21 45 22 if ( ! function_exists( 'twentyten_init' ) ) : 23 /** 24 * Set up defaults for our theme. 25 * 26 * Sets up theme defaults and tells wordpress that this is a 27 * theme that will take advantage of Post Thumbnails, Custom 28 * Background, Nav Menus and automatic feed links. To 29 * override any of the settings in a child theme, create your 30 * own twentyten_init function 31 * 32 * @uses add_theme_support() 33 */ 34 function twentyten_init() { 35 // This theme allows users to set a custom background 36 add_custom_background(); 46 /** Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */ 47 add_action( 'after_setup_theme', 'twentyten_setup' ); 48 49 /** 50 * Sets 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 runs 53 * before the init hook. The init hook is too late for some features, such as indicating 54 * support post thumbnails. 55 * 56 * To override twentyten_setup() in a child theme, remove the action hook and add your own 57 * function tied to the after_setup_theme hook. 58 * 59 * @uses add_theme_support() To add support for post thumbnails, navigation menus, and automatic feed links. 60 * @uses add_custom_background() To add support for a custom background. 61 * @uses add_editor_style() To style the visual editor. 62 * @uses load_theme_textdomain() For translation/localization support. 63 * @uses add_custom_image_header() To add support for a custom header. 64 * @uses register_default_headers() To register the default custom header images provided with the theme. 65 * @uses set_post_thumbnail_size() To set a custom post thumbnail size. 66 * 67 * @since 3.0.0 68 */ 69 function twentyten_setup() { 37 70 38 71 // This theme styles the visual editor with editor-style.css to match the theme style. 39 72 add_editor_style(); 40 73 41 // This theme needs post thumbnails74 // This theme uses post thumbnails 42 75 add_theme_support( 'post-thumbnails' ); 43 76 44 77 // This theme uses wp_nav_menu() 45 78 add_theme_support( 'nav-menus' ); 46 47 // We'll be using them for custom header images on posts and pages48 // so we want them to be 940 pixels wide by 198 pixels tall (larger images will be auto-cropped to fit)49 set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );50 79 51 80 // Add default posts and comments RSS feed links to head … … 61 90 require_once( $locale_file ); 62 91 63 // Your Changeable header business starts here 64 // No CSS, just IMG call 92 // This theme allows users to set a custom background 93 add_custom_background(); 94 95 // Your changeable header business starts here 65 96 define( 'HEADER_TEXTCOLOR', '' ); 66 define( 'HEADER_IMAGE', '%s/images/headers/forestfloor.jpg' ); // %s is theme dir uri 67 68 // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values 97 // No CSS, just IMG call. The %s is a placeholder for the theme template directory URI. 98 define( 'HEADER_IMAGE', '%s/images/headers/forestfloor.jpg' ); 99 100 // The height and width of your custom header. You can hook into the theme's own filters to change these values. 101 // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values. 69 102 define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) ); 70 103 define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) ); 71 104 105 // We'll be using post thumbnails for custom header images on posts and pages. 106 // We want them to be 940 pixels wide by 198 pixels tall (larger images will be auto-cropped to fit). 107 set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); 108 109 // Don't support text inside the header image. 72 110 define( 'NO_HEADER_TEXT', true ); 73 111 112 // Add a way for the custom header to be styled in the admin panel that controls 113 // custom headers. See twentyten_admin_header_style(), below. 74 114 add_custom_image_header( '', 'twentyten_admin_header_style' ); 75 // and thus ends the changeable header business 76 77 // Default custom headers. %s is a placeholder for the theme template directory 78 115 116 // ... and thus ends the changeable header business. 117 118 // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. 79 119 register_default_headers( array ( 80 120 'berries' => array ( … … 120 160 ) ); 121 161 } 122 endif;123 add_action( 'after_setup_theme', 'twentyten_init' );124 162 125 163 if ( ! function_exists( 'twentyten_admin_header_style' ) ) : 126 164 /** 127 * Callback to style the header image inside the admin 165 * Styles the header image displayed on the Appearance > Header admin panel. 166 * 167 * Referenced via add_custom_image_header() in twentyten_setup(). 168 * 169 * @since 3.0.0 128 170 */ 129 171 function twentyten_admin_header_style() { … … 142 184 endif; 143 185 144 if ( ! function_exists( 'twentyten_get_page_number' ) ) : 145 /** 146 * Returns the page number currently being browsed 147 * 148 * Returns a vertical bar followed by page and the page 149 * number. Is pluggable 150 * 151 * @retun string 152 */ 153 function twentyten_get_page_number() { 186 if ( ! function_exists( 'twentyten_the_page_number' ) ) : 187 /** 188 * Prints the page number currently being browsed, with a vertical bar before it. 189 * 190 * Used in Twenty Ten's header.php to add the page number to the <title> HTML tag. 191 * 192 * @since 3.0.0 193 */ 194 function twentyten_the_page_number() { 154 195 if ( get_query_var( 'paged' ) ) 155 return ' | ' . __( 'Page ' , 'twentyten' ) . get_query_var( 'paged' ); 156 } 157 endif; 158 159 if ( ! function_exists( 'twentyten_the_page_number' ) ) : 160 /** 161 * Echos the page number being browsed 162 * 163 * @uses twentyten_get_page_number 164 * 165 */ 166 function twentyten_the_page_number() { 167 echo twentyten_get_page_number(); 168 } 169 endif; 170 171 if ( ! function_exists( 'twentyten_excerpt_length' ) ) : 172 /** 173 * Sets the excerpt length to 40 charachters. Is pluggable 196 echo ' | ' . __( 'Page ' , 'twentyten' ) . get_query_var( 'paged' ); 197 } 198 endif; 199 200 /** 201 * Sets the post excerpt length to 40 characters. 202 * 203 * To override this length in a child theme, remove the filter and add your own 204 * function tied to the excerpt_length filter hook. 174 205 * 175 206 * @return int … … 178 209 return 40; 179 210 } 180 endif;181 211 add_filter( 'excerpt_length', 'twentyten_excerpt_length' ); 182 212 183 if ( ! function_exists( 'twentyten_excerpt_more' ) ) : 184 /** 185 * Sets the read more link for excerpts to something pretty 186 * 187 * @return string 188 * 213 /** 214 * Sets the "read more" link to something pretty. 215 * 216 * To override this link in a child theme, remove the filter and add your own 217 * function tied to the excerpt_more filter hook. 218 * 219 * @since 3.0.0 220 * @return string A pretty 'Continue reading' link. 189 221 */ 190 222 function twentyten_excerpt_more( $more ) { 191 223 return ' … <a href="'. get_permalink() . '">' . __('Continue reading <span class="meta-nav">→</span>', 'twentyten') . '</a>'; 192 224 } 193 endif;194 225 add_filter( 'excerpt_more', 'twentyten_excerpt_more' ); 195 226 227 /** 228 * Remove inline styles printed when the gallery shortcode is used. 229 * 230 * Galleries are styled by the theme in Twenty Ten's style.css. 231 * 232 * @return string The gallery style filter, with the styles themselves removed. 233 */ 234 function twentyten_remove_gallery_css( $css ) { 235 return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css ); 236 } 237 add_filter( 'gallery_style', 'twentyten_remove_gallery_css' ); 238 196 239 if ( ! function_exists( 'twentyten_comment' ) ) : 197 240 /** 198 * Template for comments and pingbacks 199 * 200 * Used as a callback by wp_list_comments for displaying the 201 * comments. Is pluggable 202 * 241 * Template for comments and pingbacks. 242 * 243 * To override this walker in a child theme without modifying the comments template 244 * simply create your own twentyten_comment(), and that function will be used instead. 245 * 246 * Used as a callback by wp_list_comments() for displaying the comments. 247 * 248 * @since 3.0.0 203 249 */ 204 250 function twentyten_comment( $comment, $args, $depth ) { … … 232 278 endif; 233 279 234 if ( ! function_exists( 'twentyten_remove_gallery_css' ) ) :235 /**236 * Remove inline styles on gallery shortcode237 *238 * @return string239 */240 function twentyten_remove_gallery_css( $css ) {241 return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );242 }243 endif;244 add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );245 246 280 if ( ! function_exists( 'twentyten_cat_list' ) ) : 247 281 /** … … 275 309 } 276 310 endif; 311 277 312 278 313 if ( ! function_exists( 'twentyten_term_list' ) ) : … … 314 349 endif; 315 350 316 if ( ! function_exists( 'twentyten_widgets_init' ) ) : 317 /** 318 * Register widgetized areas 319 * 351 /** 352 * Register widgetized areas, including two sidebars and four widget-ready columns in the footer. 353 * 354 * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own 355 * function tied to the init hook. 320 356 * @uses register_sidebar 321 357 */ … … 386 422 'after_title' => '</h3>', 387 423 ) ); 388 389 } 390 endif; 424 } 391 425 add_action( 'init', 'twentyten_widgets_init' );
Note: See TracChangeset
for help on using the changeset viewer.