PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/functions.php

https://github.com/ervin09/photopholio
PHP | 215 lines | 123 code | 36 blank | 56 comment | 43 complexity | 2408673ed88cb43619cc0cadc9d09fb0 MD5 | raw file
  1. <?php
  2. /**
  3. * Custom Nav Menus
  4. */
  5. register_nav_menus( array(
  6. 'head' => 'Header Menu',
  7. 'foot' => 'Footer Menu'
  8. ) );
  9. /**
  10. * Featured Images
  11. */
  12. add_theme_support('post-thumbnails' );
  13. add_image_size('hard', 980, 400, true );
  14. add_image_size('flex', 560, 999 );
  15. /**
  16. * Widgetized Sections
  17. */
  18. function base_widgets_init() {
  19. register_sidebar( array(
  20. 'name' => __( 'Sidebar', 'base' ),
  21. 'before_title' => '<h3>',
  22. 'after_title' => '</h3>',
  23. 'before_widget' => '<div id="%1$s" class="widget %2$s">',
  24. 'after_widget' => '</div>',
  25. ) );
  26. register_sidebar( array(
  27. 'name' => __( 'Footer', 'base' ),
  28. 'before_title' => '<h3>',
  29. 'after_title' => '</h3>',
  30. 'before_widget' => '<div id="%1$s" class="footget %2$s">',
  31. 'after_widget' => '</div>',
  32. ) );
  33. }
  34. add_action( 'widgets_init', 'base_widgets_init' );
  35. function scripts_and_styles() {
  36. if( is_singular() && comments_open() )
  37. wp_enqueue_style('comment-style', get_bloginfo('template_url') . '/css/comments.css');
  38. //wp_enqueue_script('jquery');
  39. //wp_enqueue_script('cform', get_stylesheet_directory_uri() . '/js/cform.js', array('jquery'), NULL );
  40. //wp_enqueue_script('custom', get_bloginfo('template_url') . '/js/custom.js', array('jquery'));
  41. }
  42. add_action('wp_enqueue_scripts', 'scripts_and_styles');
  43. /**
  44. * Is Ajax?
  45. * Check if it is an ajax request
  46. */
  47. function is_ajax() {
  48. return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
  49. }
  50. /**
  51. * Shorten
  52. * Get part of the content by defining the number of characters.
  53. *
  54. * @author: Baki Goxhaj
  55. * @author URI: http://www.wplancer.com/
  56. *
  57. * @param int $len Required. Number of characters to show
  58. * @param string $str Optional, default is empty. Full text to be shortened.
  59. * @param string $more Optional. Read more link text.
  60. * @param bool $cut Optional, default is true. Remove half-cut words from the shortened text.
  61. * @return string HTML content.
  62. */
  63. function shorten( $len, $str = '', $more = 'Read more &rarr;', $cut = true ) {
  64. if( $str == '' ) $str = get_the_content();
  65. $str = strip_tags( strip_shortcodes( $str ) );
  66. $read = '<a href="' . get_permalink() . '" title="' . get_the_title() . '">' . $more . '</a>';
  67. if( strlen( $str ) <= $len )
  68. echo $str;
  69. else
  70. echo ( $cut ? substr( $str, 0, strrpos( substr( $str, 0, $len ), ' ' ) ) : substr( $str, 0, $len ) ) . '... ' . $read;
  71. }
  72. /**
  73. * The Breadcrumb
  74. * Adds a simple but highly customizable breadcrumb to your WordPress website
  75. * @author: Baki Goxhaj of WPlancer.Com
  76. */
  77. function the_breadcrumb( $sep = ' / ' ) {
  78. $out = '<a href="'. get_bloginfo('url') .'">Home</a>';
  79. if( is_category() )
  80. $out .= $sep . single_cat_title( '', false );
  81. if( is_single() )
  82. $out .= $sep . get_the_category_list( $sep, 'multiple') . $sep . single_post_title( '', false );
  83. if( is_page() )
  84. $out .= $sep . single_post_title( '', false );
  85. if( is_singular('event') )
  86. $out .= $sep . '<a href="' . get_permalink(371) . '">Events</a>' . $sep . single_post_title( '', false );
  87. if( is_search() )
  88. $out .= $sep . 'Search results for "' . get_search_query() . '"';
  89. if( is_author() )
  90. $out .= $sep . 'All posts by ' . get_the_author_meta( 'display_name', get_query_var('author') );
  91. echo $out;
  92. }
  93. function the_location() {
  94. global $post;
  95. if( is_archive() )
  96. $where = 'Browsing Website <em>Archive</em>';
  97. if( is_category() )
  98. $where = 'Browsing <em>' . single_cat_title('', false) . '</em> Category';
  99. if( is_tag() )
  100. $where = 'Browsing <em>' . single_tag_title('', false) . '</em> Tag';
  101. if( is_tax() )
  102. $where = 'Browsing <em>' . single_term_title('', false) . '</em> Archive';
  103. if( is_author() )
  104. $where = 'Browsing all posts by <em>' . get_the_author_meta( 'display_name', get_query_var('author') ) . '</em>' ;
  105. if( is_search() )
  106. $where = 'Browsing <em>' . get_search_query() . '</em> Search Results';
  107. if( is_404() )
  108. $where = 'Nothing Found - <em>Sorry!<em>';
  109. echo $where;
  110. }
  111. /**
  112. * A pagination function
  113. * @param integer $range: The range of the slider, works best with even numbers
  114. * Used WP functions:
  115. * get_pagenum_link($i) - creates the link, e.g. http://site.com/page/4
  116. * previous_posts_link(' « '); - returns the Previous page link
  117. * next_posts_link(' » '); - returns the Next page link
  118. */
  119. function the_pagination( $range = 4, $wrap = true ){
  120. // $paged - number of the current page
  121. global $paged, $wp_query;
  122. // How many pages do we have?
  123. if( !isset( $max_page ) )
  124. $max_page = $wp_query->max_num_pages;
  125. // We need the pagination only if there is more than 1 page
  126. if( $max_page > 1 ) :
  127. if( $wrap == true ) echo '<div class="pagination">';
  128. if ( !$paged ) $paged = 1;
  129. // On the first page, don't put the First page link
  130. if( $paged != 1 ) {
  131. echo '<a class="jump first" href=' . get_pagenum_link( 1 ) . '>First</a>';
  132. // To the previous page
  133. echo '<a href="'. previous_posts( false ) .'" class="prev"> « </a>';
  134. //previous_posts_link(' « ');
  135. }
  136. // We need the sliding effect only if there are more pages than is the sliding range
  137. if ( $max_page > $range ) {
  138. // When closer to the beginning
  139. if ( $paged < $range ) {
  140. for( $i = 1; $i <= ( $range + 1 ); $i++ ) :
  141. echo '<a href="' . get_pagenum_link( $i ) .'"';
  142. if( $i == $paged ) echo 'class="current"';
  143. echo ">$i</a>";
  144. endfor;
  145. }
  146. // When closer to the end
  147. elseif( $paged >= ( $max_page - ceil(( $range/2 )) ) ) {
  148. for( $i = $max_page - $range; $i <= $max_page; $i++ ) :
  149. echo "<a href='" . get_pagenum_link($i) ."'";
  150. if( $i==$paged) echo "class='current'";
  151. echo ">$i</a>";
  152. endfor;
  153. }
  154. // Somewhere in the middle
  155. elseif( $paged >= $range && $paged < ($max_page - ceil(($range/2)))){
  156. for($i = ($paged - ceil($range/2)); $i <= ($paged + ceil(($range/2))); $i++):
  157. echo "<a href='" . get_pagenum_link($i) ."'";
  158. if($i==$paged) echo "class='current'";
  159. echo ">$i</a>";
  160. endfor;
  161. }
  162. }
  163. // Less pages than the range, no sliding effect needed
  164. else {
  165. for( $i = 1; $i <= $max_page; $i++ ) :
  166. echo "<a href='" . get_pagenum_link($i) ."'";
  167. if($i==$paged) echo "class='current'";
  168. echo ">$i</a>";
  169. endfor;
  170. }
  171. // Next page
  172. echo '<a href="'. next_posts( 0, false ) .'" class="next"> » </a>';
  173. //next_posts_link(' » ');
  174. // On the last page, don't put the Last page link
  175. if( $paged != $max_page )
  176. echo '<a class="jump last" href=' . get_pagenum_link( $max_page ) . '>Last</a>';
  177. if( $wrap == true ) echo '</div>';
  178. endif;
  179. }