PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/Starkers/functions.php

https://github.com/aspaceafo/aspace-theme
PHP | 561 lines | 273 code | 56 blank | 232 comment | 25 complexity | d263050dc2177ea2a6c510a5b277beeb MD5 | raw file
Possible License(s): AGPL-1.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 Starkers
  38. * @since Starkers 3.0
  39. */
  40. /**
  41. * Set the content width based on the theme's design and stylesheet.
  42. *
  43. * Used to set the width of images and content. Should be equal to the width the theme
  44. * is designed for, generally via the style.css stylesheet.
  45. */
  46. if ( ! isset( $content_width ) )
  47. $content_width = 640;
  48. /** Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */
  49. add_action( 'after_setup_theme', 'twentyten_setup' );
  50. if ( ! function_exists( 'twentyten_setup' ) ):
  51. /**
  52. * Sets up theme defaults and registers support for various WordPress features.
  53. *
  54. * Note that this function is hooked into the after_setup_theme hook, which runs
  55. * before the init hook. The init hook is too late for some features, such as indicating
  56. * support post thumbnails.
  57. *
  58. * To override twentyten_setup() in a child theme, add your own twentyten_setup to your child theme's
  59. * functions.php file.
  60. *
  61. * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
  62. * @uses register_nav_menus() To add support for navigation menus.
  63. * @uses add_custom_background() To add support for a custom background.
  64. * @uses add_editor_style() To style the visual editor.
  65. * @uses load_theme_textdomain() For translation/localization support.
  66. * @uses add_custom_image_header() To add support for a custom header.
  67. * @uses register_default_headers() To register the default custom header images provided with the theme.
  68. * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  69. *
  70. * @since Twenty Ten 1.0
  71. */
  72. function twentyten_setup() {
  73. // This theme styles the visual editor with editor-style.css to match the theme style.
  74. add_editor_style();
  75. // This theme uses post thumbnails
  76. add_theme_support( 'post-thumbnails' );
  77. // Add default posts and comments RSS feed links to head
  78. add_theme_support( 'automatic-feed-links' );
  79. // Make theme available for translation
  80. // Translations can be filed in the /languages/ directory
  81. load_theme_textdomain( 'twentyten', TEMPLATEPATH . '/languages' );
  82. $locale = get_locale();
  83. $locale_file = TEMPLATEPATH . "/languages/$locale.php";
  84. if ( is_readable( $locale_file ) )
  85. require_once( $locale_file );
  86. // This theme uses wp_nav_menu() in one location.
  87. register_nav_menus( array(
  88. 'primary' => __( 'Primary Navigation', 'twentyten' ),
  89. ) );
  90. // This theme allows users to set a custom background
  91. add_custom_background();
  92. // Your changeable header business starts here
  93. define( 'HEADER_TEXTCOLOR', '' );
  94. // No CSS, just IMG call. The %s is a placeholder for the theme template directory URI.
  95. define( 'HEADER_IMAGE', '%s/images/headers/path.jpg' );
  96. // The height and width of your custom header. You can hook into the theme's own filters to change these values.
  97. // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values.
  98. define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) );
  99. define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) );
  100. // We'll be using post thumbnails for custom header images on posts and pages.
  101. // We want them to be 940 pixels wide by 198 pixels tall.
  102. // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
  103. set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
  104. // Don't support text inside the header image.
  105. define( 'NO_HEADER_TEXT', true );
  106. // Add a way for the custom header to be styled in the admin panel that controls
  107. // custom headers. See twentyten_admin_header_style(), below.
  108. add_custom_image_header( '', 'twentyten_admin_header_style' );
  109. // ... and thus ends the changeable header business.
  110. // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
  111. register_default_headers( array(
  112. 'berries' => array(
  113. 'url' => '%s/images/headers/starkers.png',
  114. 'thumbnail_url' => '%s/images/headers/starkers-thumbnail.png',
  115. /* translators: header image description */
  116. 'description' => __( 'Starkers', 'twentyten' )
  117. )
  118. ) );
  119. }
  120. endif;
  121. if ( ! function_exists( 'twentyten_admin_header_style' ) ) :
  122. /**
  123. * Styles the header image displayed on the Appearance > Header admin panel.
  124. *
  125. * Referenced via add_custom_image_header() in twentyten_setup().
  126. *
  127. * @since Twenty Ten 1.0
  128. */
  129. function twentyten_admin_header_style() {
  130. ?>
  131. <style type="text/css">
  132. /* Shows the same border as on front end */
  133. #headimg {
  134. border-bottom: 1px solid #000;
  135. border-top: 4px solid #000;
  136. }
  137. /* If NO_HEADER_TEXT is false, you would style the text with these selectors:
  138. #headimg #name { }
  139. #headimg #desc { }
  140. */
  141. </style>
  142. <?php
  143. }
  144. endif;
  145. /**
  146. * Makes some changes to the <title> tag, by filtering the output of wp_title().
  147. *
  148. * If we have a site description and we're viewing the home page or a blog posts
  149. * page (when using a static front page), then we will add the site description.
  150. *
  151. * If we're viewing a search result, then we're going to recreate the title entirely.
  152. * We're going to add page numbers to all titles as well, to the middle of a search
  153. * result title and the end of all other titles.
  154. *
  155. * The site title also gets added to all titles.
  156. *
  157. * @since Twenty Ten 1.0
  158. *
  159. * @param string $title Title generated by wp_title()
  160. * @param string $separator The separator passed to wp_title(). Twenty Ten uses a
  161. * vertical bar, "|", as a separator in header.php.
  162. * @return string The new title, ready for the <title> tag.
  163. */
  164. function twentyten_filter_wp_title( $title, $separator ) {
  165. // Don't affect wp_title() calls in feeds.
  166. if ( is_feed() )
  167. return $title;
  168. // The $paged global variable contains the page number of a listing of posts.
  169. // The $page global variable contains the page number of a single post that is paged.
  170. // We'll display whichever one applies, if we're not looking at the first page.
  171. global $paged, $page;
  172. if ( is_search() ) {
  173. // If we're a search, let's start over:
  174. $title = sprintf( __( 'Search results for %s', 'twentyten' ), '"' . get_search_query() . '"' );
  175. // Add a page number if we're on page 2 or more:
  176. if ( $paged >= 2 )
  177. $title .= " $separator " . sprintf( __( 'Page %s', 'twentyten' ), $paged );
  178. // Add the site name to the end:
  179. $title .= " $separator " . get_bloginfo( 'name', 'display' );
  180. // We're done. Let's send the new title back to wp_title():
  181. return $title;
  182. }
  183. // Otherwise, let's start by adding the site name to the end:
  184. $title .= get_bloginfo( 'name', 'display' );
  185. // If we have a site description and we're on the home/front page, add the description:
  186. $site_description = get_bloginfo( 'description', 'display' );
  187. if ( $site_description && ( is_home() || is_front_page() ) )
  188. $title .= " $separator " . $site_description;
  189. // Add a page number if necessary:
  190. if ( $paged >= 2 || $page >= 2 )
  191. $title .= " $separator " . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) );
  192. // Return the new title to wp_title():
  193. return $title;
  194. }
  195. add_filter( 'wp_title', 'twentyten_filter_wp_title', 10, 2 );
  196. /**
  197. * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  198. *
  199. * To override this in a child theme, remove the filter and optionally add
  200. * your own function tied to the wp_page_menu_args filter hook.
  201. *
  202. * @since Twenty Ten 1.0
  203. */
  204. function twentyten_page_menu_args( $args ) {
  205. $args['show_home'] = true;
  206. return $args;
  207. }
  208. add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );
  209. /**
  210. * Sets the post excerpt length to 40 characters.
  211. *
  212. * To override this length in a child theme, remove the filter and add your own
  213. * function tied to the excerpt_length filter hook.
  214. *
  215. * @since Twenty Ten 1.0
  216. * @return int
  217. */
  218. function twentyten_excerpt_length( $length ) {
  219. return 40;
  220. }
  221. add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
  222. /**
  223. * Returns a "Continue Reading" link for excerpts
  224. *
  225. * @since Twenty Ten 1.0
  226. * @return string "Continue Reading" link
  227. */
  228. function twentyten_continue_reading_link() {
  229. //turned off
  230. //return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) . '</a>';
  231. }
  232. /**
  233. * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link().
  234. *
  235. * To override this in a child theme, remove the filter and add your own
  236. * function tied to the excerpt_more filter hook.
  237. *
  238. * @since Twenty Ten 1.0
  239. * @return string An ellipsis
  240. */
  241. function twentyten_auto_excerpt_more( $more ) {
  242. return ' &hellip;' . twentyten_continue_reading_link();
  243. }
  244. add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
  245. /**
  246. * Adds a pretty "Continue Reading" link to custom post excerpts.
  247. *
  248. * To override this link in a child theme, remove the filter and add your own
  249. * function tied to the get_the_excerpt filter hook.
  250. *
  251. * @since Twenty Ten 1.0
  252. * @return string Excerpt with a pretty "Continue Reading" link
  253. */
  254. function twentyten_custom_excerpt_more( $output ) {
  255. if ( has_excerpt() && ! is_attachment() ) {
  256. $output .= twentyten_continue_reading_link();
  257. }
  258. return $output;
  259. }
  260. add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
  261. /**
  262. * Remove inline styles printed when the gallery shortcode is used.
  263. *
  264. * Galleries are styled by the theme in Twenty Ten's style.css.
  265. *
  266. * @since Twenty Ten 1.0
  267. * @return string The gallery style filter, with the styles themselves removed.
  268. */
  269. function twentyten_remove_gallery_css( $css ) {
  270. return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
  271. }
  272. add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
  273. if ( ! function_exists( 'twentyten_comment' ) ) :
  274. /**
  275. * Template for comments and pingbacks.
  276. *
  277. * To override this walker in a child theme without modifying the comments template
  278. * simply create your own twentyten_comment(), and that function will be used instead.
  279. *
  280. * Used as a callback by wp_list_comments() for displaying the comments.
  281. *
  282. * @since Twenty Ten 1.0
  283. */
  284. function twentyten_comment( $comment, $args, $depth ) {
  285. $GLOBALS['comment'] = $comment;
  286. switch ( $comment->comment_type ) :
  287. case '' :
  288. ?>
  289. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  290. <div id="comment-<?php comment_ID(); ?>">
  291. <div class="comment-author vcard">
  292. <?php echo get_avatar( $comment, 40 ); ?>
  293. <?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
  294. </div><!-- .comment-author .vcard -->
  295. <?php if ( $comment->comment_approved == '0' ) : ?>
  296. <em><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
  297. <br />
  298. <?php endif; ?>
  299. <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
  300. <?php
  301. /* translators: 1: date, 2: time */
  302. printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
  303. ?>
  304. </div><!-- .comment-meta .commentmetadata -->
  305. <div class="comment-body"><?php comment_text(); ?></div>
  306. <div class="reply">
  307. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  308. </div><!-- .reply -->
  309. </div><!-- #comment-## -->
  310. <?php
  311. break;
  312. case 'pingback' :
  313. case 'trackback' :
  314. ?>
  315. <li class="post pingback">
  316. <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'twentyten'), ' ' ); ?></p>
  317. <?php
  318. break;
  319. endswitch;
  320. }
  321. endif;
  322. /**
  323. * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
  324. *
  325. * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own
  326. * function tied to the init hook.
  327. *
  328. * @since Twenty Ten 1.0
  329. * @uses register_sidebar
  330. */
  331. function twentyten_widgets_init() {
  332. // Area 1, located at the top of the sidebar.
  333. register_sidebar( array(
  334. 'name' => __( 'Primary Widget Area', 'twentyten' ),
  335. 'id' => 'primary-widget-area',
  336. 'description' => __( 'The primary widget area', 'twentyten' ),
  337. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  338. 'after_widget' => '</li>',
  339. 'before_title' => '<h3 class="widget-title">',
  340. 'after_title' => '</h3>',
  341. ) );
  342. // Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
  343. register_sidebar( array(
  344. 'name' => __( 'Secondary Widget Area', 'twentyten' ),
  345. 'id' => 'secondary-widget-area',
  346. 'description' => __( 'The secondary widget area', 'twentyten' ),
  347. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  348. 'after_widget' => '</li>',
  349. 'before_title' => '<h3 class="widget-title">',
  350. 'after_title' => '</h3>',
  351. ) );
  352. // Area 3, located in the footer. Empty by default.
  353. register_sidebar( array(
  354. 'name' => __( 'First Footer Widget Area', 'twentyten' ),
  355. 'id' => 'first-footer-widget-area',
  356. 'description' => __( 'The first footer widget area', 'twentyten' ),
  357. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  358. 'after_widget' => '</li>',
  359. 'before_title' => '<h3 class="widget-title">',
  360. 'after_title' => '</h3>',
  361. ) );
  362. // Area 4, located in the footer. Empty by default.
  363. register_sidebar( array(
  364. 'name' => __( 'Second Footer Widget Area', 'twentyten' ),
  365. 'id' => 'second-footer-widget-area',
  366. 'description' => __( 'The second footer widget area', 'twentyten' ),
  367. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  368. 'after_widget' => '</li>',
  369. 'before_title' => '<h3 class="widget-title">',
  370. 'after_title' => '</h3>',
  371. ) );
  372. // Area 5, located in the footer. Empty by default.
  373. register_sidebar( array(
  374. 'name' => __( 'Third Footer Widget Area', 'twentyten' ),
  375. 'id' => 'third-footer-widget-area',
  376. 'description' => __( 'The third footer widget area', 'twentyten' ),
  377. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  378. 'after_widget' => '</li>',
  379. 'before_title' => '<h3 class="widget-title">',
  380. 'after_title' => '</h3>',
  381. ) );
  382. // Area 6, located in the footer. Empty by default.
  383. register_sidebar( array(
  384. 'name' => __( 'Fourth Footer Widget Area', 'twentyten' ),
  385. 'id' => 'fourth-footer-widget-area',
  386. 'description' => __( 'The fourth footer 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. /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
  394. add_action( 'widgets_init', 'twentyten_widgets_init' );
  395. /**
  396. * Removes the default styles that are packaged with the Recent Comments widget.
  397. *
  398. * To override this in a child theme, remove the filter and optionally add your own
  399. * function tied to the widgets_init action hook.
  400. *
  401. * @since Twenty Ten 1.0
  402. */
  403. function twentyten_remove_recent_comments_style() {
  404. global $wp_widget_factory;
  405. remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
  406. }
  407. add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );
  408. if ( ! function_exists( 'twentyten_posted_on' ) ) :
  409. /**
  410. * Prints HTML with meta information for the current post—date/time and author.
  411. *
  412. * @since Twenty Ten 1.0
  413. */
  414. function twentyten_posted_on() {
  415. printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
  416. 'meta-prep meta-prep-author',
  417. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
  418. get_permalink(),
  419. esc_attr( get_the_time() ),
  420. get_the_date()
  421. ),
  422. sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
  423. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  424. sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
  425. get_the_author()
  426. )
  427. );
  428. }
  429. endif;
  430. if ( ! function_exists( 'twentyten_posted_in' ) ) :
  431. /**
  432. * Prints HTML with meta information for the current post (category, tags and permalink).
  433. *
  434. * @since Twenty Ten 1.0
  435. */
  436. function twentyten_posted_in() {
  437. // Retrieves tag list of current post, separated by commas.
  438. $tag_list = get_the_tag_list( '', ', ' );
  439. if ( $tag_list ) {
  440. $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' );
  441. } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
  442. $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' );
  443. } else {
  444. $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
  445. }
  446. // Prints the string, replacing the placeholders.
  447. printf(
  448. $posted_in,
  449. get_the_category_list( ', ' ),
  450. $tag_list,
  451. get_permalink(),
  452. the_title_attribute( 'echo=0' )
  453. );
  454. }
  455. endif;
  456. function list_all_posttypes() {
  457. global $post;
  458. echo '<ul>';
  459. rewind_posts();
  460. // Create a new WP_Query() object
  461. $wpcust = new WP_Query(
  462. array(
  463. 'post_type' => array(
  464. 'bookcurator'
  465. ),
  466. 'showposts' => '5' ) // or 10 etc. however many you want
  467. );
  468. // the $wpcust-> variable is used to call the Loop methods. not sure if required
  469. if ( $wpcust->have_posts() ):
  470. while( $wpcust->have_posts() ) : $wpcust->the_post();
  471. ?>
  472. <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  473. <?php
  474. // get the post type for each post
  475. $posttype = get_post_type( $post->ID );
  476. if ( $posttype) {
  477. echo '(' . $posttype . ')'; // display what each post is in parenthesis
  478. } ?>
  479. </li>
  480. <?php
  481. endwhile; // close the Loop
  482. endif;
  483. wp_reset_query(); // reset the Loop
  484. echo '</ul>';
  485. if ( !is_admin() ) {
  486. wp_deregister_script('jquery');
  487. wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"), false, '1.3.2');
  488. wp_enqueue_script('jquery');
  489. };
  490. } // end of list_all_posttypes() function
  491. //removed "Protected:" from titles of pwrd protected pages
  492. function the_title_trim($title) {
  493. $title = attribute_escape($title);
  494. $findthese = array(
  495. '#Protected:#',
  496. '#Private:#'
  497. );
  498. $replacewith = array(
  499. '', // What to replace "Protected:" with
  500. '' // What to replace "Private:" with
  501. );
  502. $title = preg_replace($findthese, $replacewith, $title);
  503. return $title;
  504. }
  505. add_filter('the_title', 'the_title_trim');