Advertisement
STATEDLIGHT

Theme Functions

Jan 21st, 2013
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.87 KB | None | 0 0
  1. <?php
  2.  
  3. require_once(get_template_directory() . '/admin/admin-functions.php');
  4. require_once(get_template_directory() . '/admin/admin-interface.php');
  5. require_once(get_template_directory() . '/admin/theme-settings.php');
  6.  
  7. /* ENQUE SCRIPTS */
  8. function tiger_scripts() {
  9. wp_enqueue_script( 'jquery' );
  10. wp_enqueue_script( 'jquery-ui-core' );
  11. wp_enqueue_script( 'jquery-ui-tabs' );
  12. wp_enqueue_script( 'theme-script', get_template_directory_uri() . '/tiger.js', 'jquery' );
  13. }
  14. add_action('init', 'tiger_scripts');
  15.  
  16. /* SET CONTENT WIDTH */
  17. if ( ! isset( $content_width ) ) $content_width = 640;
  18.  
  19. /* ADD EDITOR STYLE SUPPORT */
  20. add_theme_support('editor_style');
  21. add_editor_style('editor-style.css');
  22.  
  23. /* ENABLE AUTOMATIC FEED LINKS */
  24. add_theme_support( 'automatic-feed-links' );
  25.  
  26. /* ENABLE THUMBNAILS */
  27. add_theme_support( 'post-thumbnails' );
  28. add_image_size( 'blog-thumb', 300, 164, true );
  29.  
  30. /* REGISTER PRIMARY MENU */
  31. function tiger_register_menus() {
  32.  
  33. register_nav_menus( array(
  34. 'main-menu' => __( 'Primary Navigation', 'tiger' ),
  35. ) );
  36. }
  37.  
  38. add_action ('init', 'tiger_register_menus' );
  39.  
  40. /* ADD ANALYTICS CODE TO WP_HEAD */
  41. add_action('wp_head', 'tiger_googleanalytics');
  42. function tiger_googleanalytics() {
  43. $tiger_google_analytics = get_option('tiger_google_analytics');
  44. echo $tiger_google_analytics;
  45. }
  46.  
  47. /* ADD FAVICON CODE TO WP_HEAD */
  48. add_action('wp_head', 'tiger_favicon');
  49. function tiger_favicon() {
  50. $tiger_favicon = get_option('tiger_favicon');
  51. if ($tiger_favicon):
  52. echo '<link rel="shortcut icon" type="image/x-icon" href="'.$tiger_favicon.'" />';
  53. endif;
  54. }
  55.  
  56. /* REGISTER SIDEBAR */
  57. add_action( 'widgets_init', 'tiger_sidebars' );
  58. function tiger_sidebars() {
  59. register_sidebar(
  60. array(
  61. 'id' => 'right',
  62. 'name' => __( 'Right Sidebar', 'tiger' ),
  63. 'description' => __( 'The sidebar which appears in the right hand column', 'tiger' ),
  64. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  65. 'after_widget' => "</li>",
  66. 'before_title' => '<h3 class="widget-title">',
  67. 'after_title' => '</h3>',
  68. )
  69. );
  70. }
  71.  
  72. /* TRUNCATE TITLES */
  73. function tiger_truncate_title($amount,$echo=true) {
  74. $truncate = get_the_title();
  75. if ( strlen($truncate) <= $amount ) $echo_out = ''; else $echo_out = '...';
  76. $truncate = substr( $truncate, 0, $amount );
  77. if ($echo) {
  78. echo $truncate;
  79. echo $echo_out;
  80. }
  81. else { return ($truncate . $echo_out); }
  82. }
  83.  
  84. /* TRUNCATE POST EXCERPTS */
  85. function tiger_truncate_post($amount,$quote_after=false) {
  86. $truncate = get_the_content();
  87. $truncate = apply_filters('the_content', $truncate);
  88. $truncate = preg_replace('@<script[^>]*?>.*?</script>@si', '', $truncate);
  89. $truncate = preg_replace('@<style[^>]*?>.*?</style>@si', '', $truncate);
  90. $truncate = strip_tags($truncate);
  91. $truncate = substr($truncate, 0, strrpos(substr($truncate, 0, $amount), ' '));
  92. echo $truncate;
  93. echo "...";
  94. if ($quote_after) echo('"');
  95. }
  96.  
  97. /* BREADCRUMBS */
  98. function tiger_breadcrumbs() {
  99.  
  100. $showOnHome = 0;
  101. $delimiter = '&gt;';
  102. $home = 'Home';
  103. $showCurrent = 1;
  104. $before = '<span class="current">';
  105. $after = '</span>';
  106.  
  107. global $post;
  108. $homeLink = home_url();
  109.  
  110. if (is_home() || is_front_page()) {
  111.  
  112. if ($showOnHome == 1) echo '
  113. <div id="crumbs"><a href="' . $homeLink . '">' . $home . '</a></div>
  114.  
  115. ';
  116.  
  117. } else {
  118.  
  119. echo '
  120. <div id="crumbs">
  121. <a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' ';
  122.  
  123. if ( is_category() ) {
  124. global $wp_query;
  125. $cat_obj = $wp_query->get_queried_object();
  126. $thisCat = $cat_obj->term_id;
  127. $thisCat = get_category($thisCat);
  128. $parentCat = get_category($thisCat->parent);
  129. if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
  130. echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after;
  131.  
  132. } elseif ( is_search() ) {
  133. echo $before . 'Search results for "' . get_search_query() . '"' . $after;
  134.  
  135. } elseif ( is_day() ) {
  136. echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
  137. echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
  138. echo $before . get_the_time('d') . $after;
  139.  
  140. } elseif ( is_month() ) {
  141. echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
  142. echo $before . get_the_time('F') . $after;
  143.  
  144. } elseif ( is_year() ) {
  145. echo $before . get_the_time('Y') . $after;
  146.  
  147. } elseif ( is_single() && !is_attachment() ) {
  148. if ( get_post_type() != 'post' ) {
  149. $post_type = get_post_type_object(get_post_type());
  150. $slug = $post_type->rewrite;
  151. echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';
  152. if ($showCurrent == 1) echo $before . get_the_title() . $after;
  153. } else {
  154. $cat = get_the_category(); $cat = $cat[0];
  155. echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
  156. if ($showCurrent == 1) echo $before . get_the_title() . $after;
  157. }
  158.  
  159. } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
  160. $post_type = get_post_type_object(get_post_type());
  161. echo $before . $post_type->labels->singular_name . $after;
  162.  
  163. } elseif ( is_attachment() ) {
  164. $parent = get_post($post->post_parent);
  165. $cat = get_the_category($parent->ID); $cat = $cat[0];
  166. echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
  167. echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
  168. if ($showCurrent == 1) echo $before . get_the_title() . $after;
  169.  
  170. } elseif ( is_page() && !$post->post_parent ) {
  171. if ($showCurrent == 1) echo $before . get_the_title() . $after;
  172.  
  173. } elseif ( is_page() && $post->post_parent ) {
  174. $parent_id = $post->post_parent;
  175. $breadcrumbs = array();
  176. while ($parent_id) {
  177. $page = get_page($parent_id);
  178. $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
  179. $parent_id = $page->post_parent;
  180. }
  181. $breadcrumbs = array_reverse($breadcrumbs);
  182. foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
  183. if ($showCurrent == 1) echo $before . get_the_title() . $after;
  184.  
  185. } elseif ( is_tag() ) {
  186. echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;
  187.  
  188. } elseif ( is_author() ) {
  189. global $author;
  190. $userdata = get_userdata($author);
  191. echo $before . 'Articles posted by ' . $userdata->display_name . $after;
  192.  
  193. } elseif ( is_404() ) {
  194. echo $before . 'Error 404' . $after;
  195. }
  196.  
  197. if ( get_query_var('paged') ) {
  198. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
  199. echo __('Page', 'tiger') . ' ' . get_query_var('paged');
  200. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
  201. }
  202.  
  203. echo '</div>
  204. ';
  205.  
  206. }
  207. }
  208.  
  209. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement