Advertisement
turiyamoore

functions.php

Nov 17th, 2011
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.43 KB | None | 0 0
  1. <?php
  2. /**
  3. * TwentyTen 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, 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 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', 'twentyten_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_Ten
  38. * @since Twenty Ten 1.0
  39. */
  40.  
  41. /**
  42. * Set the content width based on the theme's design and stylesheet.
  43. *
  44. * Used to set the width of images and content. Should be equal to the width the theme
  45. * is designed for, generally via the style.css stylesheet.
  46. */
  47. if ( ! isset( $content_width ) )
  48. $content_width = 640;
  49.  
  50. /** Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */
  51. add_action( 'after_setup_theme', 'twentyten_setup' );
  52.  
  53. if ( ! function_exists( 'twentyten_setup' ) ):
  54. /**
  55. * Sets up theme defaults and registers support for various WordPress features.
  56. *
  57. * Note that this function is hooked into the after_setup_theme hook, which runs
  58. * before the init hook. The init hook is too late for some features, such as indicating
  59. * support post thumbnails.
  60. *
  61. * To override twentyten_setup() in a child theme, add your own twentyten_setup to your child theme's
  62. * functions.php file.
  63. *
  64. * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
  65. * @uses register_nav_menus() To add support for navigation menus.
  66. * @uses add_custom_background() To add support for a custom background.
  67. * @uses add_editor_style() To style the visual editor.
  68. * @uses load_theme_textdomain() For translation/localization support.
  69. * @uses add_custom_image_header() To add support for a custom header.
  70. * @uses register_default_headers() To register the default custom header images provided with the theme.
  71. * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  72. *
  73. * @since Twenty Ten 1.0
  74. */
  75. function twentyten_setup() {
  76.  
  77. // This theme styles the visual editor with editor-style.css to match the theme style.
  78. add_editor_style();
  79.  
  80. // Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories.
  81. add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
  82.  
  83. // This theme uses post thumbnails
  84. add_theme_support( 'post-thumbnails' );
  85.  
  86. // Add default posts and comments RSS feed links to head
  87. add_theme_support( 'automatic-feed-links' );
  88.  
  89. // Make theme available for translation
  90. // Translations can be filed in the /languages/ directory
  91. load_theme_textdomain( 'twentyten', TEMPLATEPATH . '/languages' );
  92.  
  93. $locale = get_locale();
  94. $locale_file = TEMPLATEPATH . "/languages/$locale.php";
  95. if ( is_readable( $locale_file ) )
  96. require_once( $locale_file );
  97.  
  98. // This theme uses wp_nav_menu() in one location.
  99. register_nav_menus( array(
  100. 'primary' => __( 'Primary Navigation', 'twentyten' ),
  101. ) );
  102.  
  103. // This theme allows users to set a custom background
  104. add_custom_background();
  105.  
  106. // Your changeable header business starts here
  107. if ( ! defined( 'HEADER_TEXTCOLOR' ) )
  108. define( 'HEADER_TEXTCOLOR', '' );
  109.  
  110. // No CSS, just IMG call. The %s is a placeholder for the theme template directory URI.
  111. if ( ! defined( 'HEADER_IMAGE' ) )
  112. define( 'HEADER_IMAGE', '%s/images/headers/path.jpg' );
  113.  
  114. // The height and width of your custom header. You can hook into the theme's own filters to change these values.
  115. // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values.
  116. define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) );
  117. define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) );
  118.  
  119. // We'll be using post thumbnails for custom header images on posts and pages.
  120. // We want them to be 940 pixels wide by 198 pixels tall.
  121. // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
  122. set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
  123.  
  124. // Don't support text inside the header image.
  125. if ( ! defined( 'NO_HEADER_TEXT' ) )
  126. define( 'NO_HEADER_TEXT', true );
  127.  
  128. // Add a way for the custom header to be styled in the admin panel that controls
  129. // custom headers. See twentyten_admin_header_style(), below.
  130. add_custom_image_header( '', 'twentyten_admin_header_style' );
  131.  
  132. // ... and thus ends the changeable header business.
  133.  
  134. // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
  135. register_default_headers( array(
  136. 'berries' => array(
  137. 'url' => '%s/images/headers/berries.jpg',
  138. 'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg',
  139. /* translators: header image description */
  140. 'description' => __( 'Berries', 'twentyten' )
  141. ),
  142. 'cherryblossom' => array(
  143. 'url' => '%s/images/headers/cherryblossoms.jpg',
  144. 'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg',
  145. /* translators: header image description */
  146. 'description' => __( 'Cherry Blossoms', 'twentyten' )
  147. ),
  148. 'concave' => array(
  149. 'url' => '%s/images/headers/concave.jpg',
  150. 'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg',
  151. /* translators: header image description */
  152. 'description' => __( 'Concave', 'twentyten' )
  153. ),
  154. 'fern' => array(
  155. 'url' => '%s/images/headers/fern.jpg',
  156. 'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg',
  157. /* translators: header image description */
  158. 'description' => __( 'Fern', 'twentyten' )
  159. ),
  160. 'forestfloor' => array(
  161. 'url' => '%s/images/headers/forestfloor.jpg',
  162. 'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg',
  163. /* translators: header image description */
  164. 'description' => __( 'Forest Floor', 'twentyten' )
  165. ),
  166. 'inkwell' => array(
  167. 'url' => '%s/images/headers/inkwell.jpg',
  168. 'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg',
  169. /* translators: header image description */
  170. 'description' => __( 'Inkwell', 'twentyten' )
  171. ),
  172. 'path' => array(
  173. 'url' => '%s/images/headers/path.jpg',
  174. 'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg',
  175. /* translators: header image description */
  176. 'description' => __( 'Path', 'twentyten' )
  177. ),
  178. 'sunset' => array(
  179. 'url' => '%s/images/headers/sunset.jpg',
  180. 'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg',
  181. /* translators: header image description */
  182. 'description' => __( 'Sunset', 'twentyten' )
  183. )
  184. ) );
  185. }
  186. endif;
  187.  
  188. if ( ! function_exists( 'twentyten_admin_header_style' ) ) :
  189. /**
  190. * Styles the header image displayed on the Appearance > Header admin panel.
  191. *
  192. * Referenced via add_custom_image_header() in twentyten_setup().
  193. *
  194. * @since Twenty Ten 1.0
  195. */
  196. function twentyten_admin_header_style() {
  197. ?>
  198. <style type="text/css">
  199. /* Shows the same border as on front end */
  200. #headimg {
  201. border-bottom: 1px solid #000;
  202. border-top: 4px solid #000;
  203. }
  204. /* If NO_HEADER_TEXT is false, you would style the text with these selectors:
  205. #headimg #name { }
  206. #headimg #desc { }
  207. */
  208. </style>
  209. <?php
  210. }
  211. endif;
  212.  
  213. /**
  214. * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  215. *
  216. * To override this in a child theme, remove the filter and optionally add
  217. * your own function tied to the wp_page_menu_args filter hook.
  218. *
  219. * @since Twenty Ten 1.0
  220. */
  221. function twentyten_page_menu_args( $args ) {
  222. $args['show_home'] = true;
  223. return $args;
  224. }
  225. add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );
  226.  
  227. /**
  228. * Sets the post excerpt length to 40 characters.
  229. *
  230. * To override this length in a child theme, remove the filter and add your own
  231. * function tied to the excerpt_length filter hook.
  232. *
  233. * @since Twenty Ten 1.0
  234. * @return int
  235. */
  236. function twentyten_excerpt_length( $length ) {
  237. return 40;
  238. }
  239. add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
  240.  
  241. /**
  242. * Returns a "Continue Reading" link for excerpts
  243. *
  244. * @since Twenty Ten 1.0
  245. * @return string "Continue Reading" link
  246. */
  247. function twentyten_continue_reading_link() {
  248. return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) . '</a>';
  249. }
  250.  
  251. /**
  252. * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link().
  253. *
  254. * To override this in a child theme, remove the filter and add your own
  255. * function tied to the excerpt_more filter hook.
  256. *
  257. * @since Twenty Ten 1.0
  258. * @return string An ellipsis
  259. */
  260. function twentyten_auto_excerpt_more( $more ) {
  261. return ' &hellip;' . twentyten_continue_reading_link();
  262. }
  263. add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
  264.  
  265. /**
  266. * Adds a pretty "Continue Reading" link to custom post excerpts.
  267. *
  268. * To override this link in a child theme, remove the filter and add your own
  269. * function tied to the get_the_excerpt filter hook.
  270. *
  271. * @since Twenty Ten 1.0
  272. * @return string Excerpt with a pretty "Continue Reading" link
  273. */
  274. function twentyten_custom_excerpt_more( $output ) {
  275. if ( has_excerpt() && ! is_attachment() ) {
  276. $output .= twentyten_continue_reading_link();
  277. }
  278. return $output;
  279. }
  280. add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
  281.  
  282. /**
  283. * Remove inline styles printed when the gallery shortcode is used.
  284. *
  285. * Galleries are styled by the theme in Twenty Ten's style.css. This is just
  286. * a simple filter call that tells WordPress to not use the default styles.
  287. *
  288. * @since Twenty Ten 1.2
  289. */
  290. add_filter('simpsid_widget_area_defaults', 'twentyten_widget_area_defaults');
  291. function twentyten_widget_area_defaults($defaults) {
  292. $defaults['before_widget'] = '<li id="%1$s" class="widget %2$s">';
  293. $defaults['after_widget'] = '</li>';
  294. $defaults['before_title'] = '<h3 class="widget-title">';
  295. $defaults['after_title'] = '</h3>';
  296. return $defaults;
  297. }
  298. add_filter( 'use_default_gallery_style', '__return_false' );
  299.  
  300. /**
  301. * Deprecated way to remove inline styles printed when the gallery shortcode is used.
  302. *
  303. * This function is no longer needed or used. Use the use_default_gallery_style
  304. * filter instead, as seen above.
  305. *
  306. * @since Twenty Ten 1.0
  307. * @deprecated Deprecated in Twenty Ten 1.2 for WordPress 3.1
  308. *
  309. * @return string The gallery style filter, with the styles themselves removed.
  310. */
  311. function twentyten_remove_gallery_css( $css ) {
  312. return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
  313. }
  314. // Backwards compatibility with WordPress 3.0.
  315. if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) )
  316. add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
  317.  
  318. if ( ! function_exists( 'twentyten_comment' ) ) :
  319. /**
  320. * Template for comments and pingbacks.
  321. *
  322. * To override this walker in a child theme without modifying the comments template
  323. * simply create your own twentyten_comment(), and that function will be used instead.
  324. *
  325. * Used as a callback by wp_list_comments() for displaying the comments.
  326. *
  327. * @since Twenty Ten 1.0
  328. */
  329. function twentyten_comment( $comment, $args, $depth ) {
  330. $GLOBALS['comment'] = $comment;
  331. switch ( $comment->comment_type ) :
  332. case '' :
  333. ?>
  334. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  335. <div id="comment-<?php comment_ID(); ?>">
  336. <div class="comment-author vcard">
  337. <?php echo get_avatar( $comment, 40 ); ?>
  338. <?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
  339. </div><!-- .comment-author .vcard -->
  340. <?php if ( $comment->comment_approved == '0' ) : ?>
  341. <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
  342. <br />
  343. <?php endif; ?>
  344.  
  345. <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
  346. <?php
  347. /* translators: 1: date, 2: time */
  348. printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
  349. ?>
  350. </div><!-- .comment-meta .commentmetadata -->
  351.  
  352. <div class="comment-body"><?php comment_text(); ?></div>
  353.  
  354. <div class="reply">
  355. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  356. </div><!-- .reply -->
  357. </div><!-- #comment-## -->
  358.  
  359. <?php
  360. break;
  361. case 'pingback' :
  362. case 'trackback' :
  363. ?>
  364. <li class="post pingback">
  365. <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p>
  366. <?php
  367. break;
  368. endswitch;
  369. }
  370. endif;
  371.  
  372. /**
  373. * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
  374. *
  375. * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own
  376. * function tied to the init hook.
  377. *
  378. * @since Twenty Ten 1.0
  379. * @uses register_sidebar
  380. */
  381. function twentyten_widgets_init() {
  382. // Area 1, located at the top of the sidebar.
  383. register_sidebar( array(
  384. 'name' => __( 'Primary Widget Area', 'twentyten' ),
  385. 'id' => 'primary-widget-area',
  386. 'description' => __( 'The primary widget area', 'twentyten' ),
  387. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  388. 'after_widget' => '</li>',
  389. 'before_title' => '<h3 class="widget-title">',
  390. 'after_title' => '</h3>',
  391. ) );
  392.  
  393. // Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
  394. register_sidebar( array(
  395. 'name' => __( 'Secondary Widget Area', 'twentyten' ),
  396. 'id' => 'secondary-widget-area',
  397. 'description' => __( 'The secondary widget area', 'twentyten' ),
  398. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  399. 'after_widget' => '</li>',
  400. 'before_title' => '<h3 class="widget-title">',
  401. 'after_title' => '</h3>',
  402. ) );
  403.  
  404. // Area 3, located in the footer. Empty by default.
  405. register_sidebar( array(
  406. 'name' => __( 'First Footer Widget Area', 'twentyten' ),
  407. 'id' => 'first-footer-widget-area',
  408. 'description' => __( 'The first footer widget area', 'twentyten' ),
  409. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  410. 'after_widget' => '</li>',
  411. 'before_title' => '<h3 class="widget-title">',
  412. 'after_title' => '</h3>',
  413. ) );
  414.  
  415. // Area 4, located in the footer. Empty by default.
  416. register_sidebar( array(
  417. 'name' => __( 'Second Footer Widget Area', 'twentyten' ),
  418. 'id' => 'second-footer-widget-area',
  419. 'description' => __( 'The second footer widget area', 'twentyten' ),
  420. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  421. 'after_widget' => '</li>',
  422. 'before_title' => '<h3 class="widget-title">',
  423. 'after_title' => '</h3>',
  424. ) );
  425.  
  426. // Area 5, located in the footer. Empty by default.
  427. register_sidebar( array(
  428. 'name' => __( 'Third Footer Widget Area', 'twentyten' ),
  429. 'id' => 'third-footer-widget-area',
  430. 'description' => __( 'The third footer widget area', 'twentyten' ),
  431. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  432. 'after_widget' => '</li>',
  433. 'before_title' => '<h3 class="widget-title">',
  434. 'after_title' => '</h3>',
  435. ) );
  436.  
  437. // Area 6, located in the footer. Empty by default.
  438. register_sidebar( array(
  439. 'name' => __( 'Fourth Footer Widget Area', 'twentyten' ),
  440. 'id' => 'fourth-footer-widget-area',
  441. 'description' => __( 'The fourth footer widget area', 'twentyten' ),
  442. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  443. 'after_widget' => '</li>',
  444. 'before_title' => '<h3 class="widget-title">',
  445. 'after_title' => '</h3>',
  446. ) );
  447. }
  448. /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
  449. add_action( 'widgets_init', 'twentyten_widgets_init' );
  450.  
  451. /**
  452. * Removes the default styles that are packaged with the Recent Comments widget.
  453. *
  454. * To override this in a child theme, remove the filter and optionally add your own
  455. * function tied to the widgets_init action hook.
  456. *
  457. * This function uses a filter (show_recent_comments_widget_style) new in WordPress 3.1
  458. * to remove the default style. Using Twenty Ten 1.2 in WordPress 3.0 will show the styles,
  459. * but they won't have any effect on the widget in default Twenty Ten styling.
  460. *
  461. * @since Twenty Ten 1.0
  462. */
  463. function twentyten_remove_recent_comments_style() {
  464. add_filter( 'show_recent_comments_widget_style', '__return_false' );
  465. }
  466.  
  467. add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );
  468.  
  469. if ( ! function_exists( 'twentyten_posted_on' ) ) :
  470. /**
  471. * Prints HTML with meta information for the current post-date/time and author.
  472. *
  473. * @since Twenty Ten 1.0
  474. */
  475. function twentyten_posted_on() {
  476. printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
  477. 'meta-prep meta-prep-author',
  478. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
  479. get_permalink(),
  480. esc_attr( get_the_time() ),
  481. get_the_date()
  482. ),
  483. sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
  484. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  485. sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
  486. get_the_author()
  487. )
  488. );
  489. }
  490. endif;
  491.  
  492. if ( ! function_exists( 'twentyten_posted_in' ) ) :
  493. /**
  494. * Prints HTML with meta information for the current post (category, tags and permalink).
  495. *
  496. * @since Twenty Ten 1.0
  497. */
  498. function twentyten_posted_in() {
  499. // Retrieves tag list of current post, separated by commas.
  500. $tag_list = get_the_tag_list( '', ', ' );
  501. if ( $tag_list ) {
  502. $posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
  503. } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
  504. $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
  505. } else {
  506. $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
  507. }
  508. // Prints the string, replacing the placeholders.
  509. printf(
  510. $posted_in,
  511. get_the_category_list( ', ' ),
  512. $tag_list,
  513. get_permalink(),
  514. the_title_attribute( 'echo=0' )
  515. );
  516. }
  517. endif;
  518.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement