1. <?php
  2. // Register the wp 3.0 Menus
  3. add_action( 'init', 'register_my_menus' );
  4.  
  5. function register_my_menus() {
  6.     register_nav_menus(
  7.         array(
  8.             'primary-menu' => __( 'Primary Menu' ),
  9.             'secondary-menu' => __( 'Secondary Menu' )
  10.         )
  11.     );
  12. }
  13.  
  14.  
  15. // Ready for theme localisation
  16. load_theme_textdomain ('framework');
  17.  
  18.  
  19.  
  20. // Register the sidebars and widget classes
  21. if ( function_exists('register_sidebar') ) {
  22.     register_sidebar(array(
  23.         'name' => 'Main Sidebar',
  24.         'before_widget' => '<div id="%1$s" class="widget %2$s">',
  25.         'after_widget' => '</div>',
  26.         'before_title' => '<h4><span>',
  27.         'after_title' => '</span></h4>',
  28.     ));
  29.     register_sidebar(array(
  30.         'name' => 'Narrow Left',
  31.         'before_widget' => '<div class="wrap">',
  32.         'after_widget' => '</div>',
  33.         'before_title' => '<h4><span>',
  34.         'after_title' => '</span></h4>',
  35.     ));
  36.     register_sidebar(array(
  37.         'name' => 'Narrow Right',
  38.         'before_widget' => '<div class="wrap">',
  39.         'after_widget' => '</div>',
  40.         'before_title' => '<h4><span>',
  41.         'after_title' => '</span></h4>',
  42.     ));
  43.     register_sidebar(array(
  44.         'name' => 'Sidebar Page',
  45.         'before_widget' => '<div id="%1$s" class="widget %2$s">',
  46.         'after_widget' => '</div>',
  47.         'before_title' => '<h4><span>',
  48.         'after_title' => '</span></h4>',
  49.     ));
  50.     register_sidebar(array(
  51.         'name' => 'Narrow Left Page',
  52.         'before_widget' => '<div class="wrap">',
  53.         'after_widget' => '</div>',
  54.         'before_title' => '<h4><span>',
  55.         'after_title' => '</span></h4>',
  56.     ));
  57.     register_sidebar(array(
  58.         'name' => 'Narrow Right Page',
  59.         'before_widget' => '<div class="wrap">',
  60.         'after_widget' => '</div>',
  61.         'before_title' => '<h4><span>',
  62.         'after_title' => '</span></h4>',
  63.     ));
  64.     register_sidebar(array(
  65.         'name' => 'Footer 1',
  66.         'before_widget' => '<div id="%1$s" class="widget %2$s">',
  67.         'after_widget' => '</div>',
  68.         'before_title' => '<h4><span>',
  69.         'after_title' => '</span></h4>',
  70.     ));
  71.     register_sidebar(array(
  72.         'name' => 'Footer 2',
  73.         'before_widget' => '<div id="%1$s" class="widget %2$s">',
  74.         'after_widget' => '</div>',
  75.         'before_title' => '<h4><span>',
  76.         'after_title' => '</span></h4>',
  77.     ));
  78.     register_sidebar(array(
  79.         'name' => 'Footer 3',
  80.         'before_widget' => '<div id="%1$s" class="widget %2$s">',
  81.         'after_widget' => '</div>',
  82.         'before_title' => '<h4><span>',
  83.         'after_title' => '</span></h4>',
  84.     ));
  85.     register_sidebar(array(
  86.         'name' => 'Footer 4',
  87.         'before_widget' => '<div id="%1$s" class="widget %2$s">',
  88.         'after_widget' => '</div>',
  89.         'before_title' => '<h4><span>',
  90.         'after_title' => '</span></h4>',
  91.     ));
  92. }
  93.  
  94.  
  95. // Add support for WP 2.9 post thumbnails
  96. if ( function_exists( 'add_theme_support' ) ) { // Added in 2.9
  97.     add_theme_support( 'post-thumbnails' );
  98.     add_image_size( 'large', 610, '', true ); // default large size
  99.     add_image_size( 'slider-preview', 275, 270, true ); // Slider large image
  100.     add_image_size( 'slider-thumbnail', 85, 60, true ); // Slider thumbnail
  101.     add_image_size( 'column-preview', 184, 144, true ); // Column size
  102.     add_image_size( 'single-large', 604, 272, true ); // Single post/page large
  103.     add_image_size( 'related-thumbnail', 130, 94, true ); // Single post/page large
  104.     add_image_size( 'post-grid', 61, 61, true ); // Post grid
  105.     add_image_size( 'category-thumbnail', 45, 45, true ); // Category list thumbnails
  106.     add_image_size( 'archive-preview', 109, 109, true ); // Archive list thumbs
  107. }
  108.  
  109.  
  110. // Add option for custom gravatar
  111. function tz_custom_gravatar( $avatar_defaults ) {
  112.     $tz_avatar = get_bloginfo('template_directory') . '/images/gravatar.png';
  113.     $avatar_defaults[$tz_avatar] = 'Custom Gravatar (/images/gravatar.png)';
  114.     return $avatar_defaults;
  115. }
  116. add_filter( 'avatar_defaults', 'tz_custom_gravatar' );
  117.  
  118.  
  119.  
  120.  
  121.  
  122. // Change Excerpt [...] to new string : WP2.8+
  123. function tz_excerpt_more($excerpt) {
  124. return str_replace('[...]', '...', $excerpt); }
  125. add_filter('wp_trim_excerpt', 'tz_excerpt_more');
  126.  
  127.  
  128. //modify the excerpt lenght in the "featured articles" section on the homepage
  129. add_filter('excerpt_length', 'my_excerpt_length');
  130. function my_excerpt_length($length) {
  131.     if(in_category(27)) { // put here the ID (4 by default) of the category used for the "featured" articles
  132.         return 70; // put the number of words (default 25)
  133.     } else {
  134.         return 50; // show 55 words for any other excerpt (or change this number also)
  135.     }
  136. }
  137.  
  138. // Replace WP local jQuery with Google latest jQuery
  139. function tz_google_jquery() {
  140.     if (!is_admin()) {
  141.         // comment out the next two lines to load the local copy of jQuery
  142.         wp_deregister_script('jquery');
  143.         wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js', false, '1.4');
  144.         wp_register_script('coda-slider', get_bloginfo('template_directory') . '/js/jquery.coda-slider-2.0.js', 'jquery');
  145.         wp_register_script('superfish', get_bloginfo('template_directory') . '/js/superfish.js', 'jquery');
  146.         wp_register_script('jquery-easing', get_bloginfo('template_directory') . '/js/jquery.easing.1.3.js', 'jquery');
  147.         wp_register_script('poshytip', get_bloginfo('template_directory') . '/js/jquery.poshytip.min.js', 'jquery');
  148.         wp_register_script('validation', get_bloginfo('template_directory') . '/js/jquery.validate.min.js', 'jquery');
  149.         wp_register_script('jquery-ui-custom', get_bloginfo('template_directory') . '/js/jquery-ui-1.8.5.custom.min.js', 'jquery');
  150.        
  151.         if (is_page_template('template-contact.php')) {
  152.             wp_enqueue_script('validation');
  153.         }
  154.     }
  155. }
  156. add_action('init', 'tz_google_jquery');
  157.  
  158.  
  159. // Add browser detection class to body tag
  160. add_filter('body_class','tz_browser_body_class');
  161. function tz_browser_body_class($classes) {
  162.     global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
  163.  
  164.     if($is_lynx) $classes[] = 'lynx';
  165.     elseif($is_gecko) $classes[] = 'gecko';
  166.     elseif($is_opera) $classes[] = 'opera';
  167.     elseif($is_NS4) $classes[] = 'ns4';
  168.     elseif($is_safari) $classes[] = 'safari';
  169.     elseif($is_chrome) $classes[] = 'chrome';
  170.     elseif($is_IE) $classes[] = 'ie';
  171.     else $classes[] = 'unknown';
  172.  
  173.     if($is_iphone) $classes[] = 'iphone';
  174.     return $classes;
  175. }
  176.  
  177. // Output the styling for the seperated Pings
  178. function tz_list_pings($comment, $args, $depth) {
  179.        $GLOBALS['comment'] = $comment; ?>
  180. <li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
  181. <?php }
  182.  
  183.  
  184. // Make a custom login logo and link
  185. function tz_custom_login_logo() {
  186.     echo '<style type="text/css">
  187.        h1 a { background-image:url('.get_bloginfo('template_directory').'/images/custom-login-logo.png) !important; }
  188.    </style>';
  189. }
  190. function tz_wp_login_url() {
  191. echo bloginfo('url');
  192. }
  193. function tz_wp_login_title() {
  194. echo get_option('blogname');
  195. }
  196.  
  197. add_action('login_head', 'tz_custom_login_logo');
  198. add_filter('login_headerurl', 'tz_wp_login_url');
  199. add_filter('login_headertitle', 'tz_wp_login_title');
  200.  
  201.  
  202. // Find and close unclosed xhtml tags
  203. function close_tags($text) {
  204.     $patt_open    = "%((?<!</)(?<=<)[\s]*[^/!>\s]+(?=>|[\s]+[^>]*[^/]>)(?!/>))%";
  205.     $patt_close    = "%((?<=</)([^>]+)(?=>))%";
  206.  
  207.     if (preg_match_all($patt_open,$text,$matches))
  208.     {
  209.         $m_open = $matches[1];
  210.         if(!empty($m_open))
  211.         {
  212.             preg_match_all($patt_close,$text,$matches2);
  213.             $m_close = $matches2[1];
  214.             if (count($m_open) > count($m_close))
  215.             {
  216.                 $m_open = array_reverse($m_open);
  217.                 foreach ($m_close as $tag) $c_tags[$tag]++;
  218.                 foreach ($m_open as $k => $tag)    if ($c_tags[$tag]--<=0) $text.='</'.$tag.'>';
  219.             }
  220.         }
  221.     }
  222.     return $text;
  223. }
  224.  
  225. // Content Limit
  226. function content($num, $more_link_text = '(more...)') {  
  227. $theContent = get_the_content($more_link_text);  
  228. $output = preg_replace('/<img[^>]+./','', $theContent);  
  229. $limit = $num+1;  
  230. $content = explode(' ', $output, $limit);  
  231. array_pop($content);  
  232. $content = implode(" ",$content);  
  233. $content = strip_tags($content, '<p><a><address><a><abbr><acronym><b><big><blockquote><br><caption><cite><class><code><col><del><dd><div><dl><dt><em><font><h1><h2><h3><h4><h5><h6><hr><i><img><ins><kbd><li><ol><p><pre><q><s><span><strike><strong><sub><sup><table><tbody><td><tfoot><tr><tt><ul><var>');
  234. echo close_tags($content);
  235. }
  236.  
  237. // Custom Comments Display
  238. function tz_comment($comment, $args, $depth) {
  239.    $GLOBALS['comment'] = $comment; ?>
  240.    
  241.     <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
  242.         <div id="comment-<?php comment_ID(); ?>">
  243.        
  244.         <div class="line"></div>
  245.         <div class="image"><?php echo get_avatar($comment,$size='61'); ?></div>
  246.        
  247.         <div class="details">
  248.        
  249.             <div class="name"><span class="author"><?php comment_author_link(); ?></span> <span class="date"><?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?> &middot; <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?></span></div>
  250.            
  251.             <?php if ($comment->comment_approved == '0') : ?>
  252.             <em><?php _e('Your comment is awaiting moderation.') ?></em>
  253.             <br />
  254.             <?php endif; ?>
  255.                
  256.             <?php comment_text() ?>
  257.            
  258.         </div><!--details-->
  259.        
  260.         </div><!--comment-<?php comment_ID(); ?>-->
  261.        
  262.    
  263. <?php
  264.         }
  265.  
  266. //work out how many posts within a category
  267. function get_category_count($input = '') {
  268.     global $wpdb;
  269.     if($input == '')
  270.     {
  271.         $category = get_the_category();
  272.         return $category[0]->category_count;
  273.     }
  274.     elseif(is_numeric($input))
  275.     {
  276.         $SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->term_taxonomy.term_id=$input";
  277.         return $wpdb->get_var($SQL);
  278.     }
  279.     else
  280.     {
  281.         $SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->terms.slug='$input'";
  282.         return $wpdb->get_var($SQL);
  283.     }
  284. }
  285.  
  286.  
  287.  
  288.  
  289.  
  290. // Add the 125x125 Ad Block Custom Widget
  291. include("functions/widget-ad125.php");
  292.  
  293. // Add the 300x250 Ad Block Custom Widget
  294. include("functions/widget-ad300x250.php");
  295.  
  296. // Add the 120x240 Ad Block Custom Widget
  297. include("functions/widget-ad120x240.php");
  298.  
  299. // Add the Latest Tweets Custom Widget
  300. include("functions/widget-tweets.php");
  301.  
  302. // Add the Flickr Photos Custom Widget
  303. include("functions/widget-flickr.php");
  304.  
  305. // Add the Custom Video Widget
  306. include("functions/widget-video.php");
  307.  
  308. // Add the Custom Tabbed Widget
  309. include("functions/widget-tabbed.php");
  310.  
  311. // Add the Rss & Twitter Count Widget
  312. include("functions/widget-rsstwitter.php");
  313.  
  314. // Add the Shortcodes
  315. include("functions/theme-shortcodes.php");
  316.  
  317. // Add the Theme Options Pages
  318. include("functions/theme-options.php");
  319. ?>