functions.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. /* Loads the Options Settings. */
  3. if ( !function_exists( 'optionsframework_init' ) ) {
  4. define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/admin/' );
  5. require_once dirname( __FILE__ ) . '/admin/options-framework.php';
  6. }
  7. /**
  8. * Define Theme setup
  9. *
  10. * @since 0.0.1
  11. */
  12. add_action( 'after_setup_theme', 'foto_setup' );
  13. function foto_setup() {
  14. /* Set the content width based on the theme's design and stylesheet. */
  15. global $content_width;
  16. if ( ! isset( $content_width ) ) $content_width = 700;
  17. /* Make foto available for translation. */
  18. load_theme_textdomain( 'foto', get_template_directory() . '/languages' );
  19. /* WordPress theme support. */
  20. add_editor_style();
  21. add_theme_support( 'automatic-feed-links' );
  22. add_theme_support( 'custom-background' );
  23. register_nav_menus( array(
  24. 'primary' => __( 'Footer Navigation', 'foto' )
  25. ) );
  26. add_theme_support( 'post-thumbnails' );
  27. add_image_size( 'foto-featured' , 700, 300, true );
  28. add_image_size( 'foto-home-thumbnail' , 220, 150, true );
  29. add_image_size( 'foto-single-thumbnail' , 700, 350, true );
  30. /* Enqueue styles & scripts. */
  31. add_action( 'wp_enqueue_scripts', 'foto_enqueue_scripts' );
  32. /* Deregister wp-pagenavi style. */
  33. add_action( 'wp_print_styles', 'foto_deregister_styles', 100 );
  34. /* Comment reply script. */
  35. add_action( 'comment_form_before', 'foto_enqueue_comment_reply_script' );
  36. /* Remove gallery inline style. */
  37. add_filter( 'use_default_gallery_style', '__return_false' );
  38. /* wp_title filter. */
  39. add_filter( 'wp_title', 'foto_title', 10, 2 );
  40. /* Custom body class. */
  41. add_filter( 'body_class', 'foto_body_classes' );
  42. /* Add new contact method. */
  43. add_filter('user_contactmethods','foto_new_contactmethods', 10, 1 );
  44. /* Customize tag cloud. */
  45. add_filter( 'widget_tag_cloud_args', 'foto_new_tag_cloud' );
  46. /* next/previous image links on image attachment pages. */
  47. add_filter( 'attachment_link', 'foto_enhanced_image_navigation', 10, 2 );
  48. /* Register sidebars & custom widget. */
  49. add_action( 'widgets_init', 'foto_widgets_init' );
  50. /**
  51. * Load required files
  52. */
  53. require( get_template_directory() . '/includes/extensions.php' );
  54. require( get_template_directory() . '/includes/templates.php' );
  55. require( get_template_directory() . '/includes/options-functions.php' );
  56. } // end foto_setup
  57. /**
  58. * Enqueue styles & scripts.
  59. *
  60. * @since 0.0.1
  61. */
  62. function foto_enqueue_scripts() {
  63. global $post;
  64. wp_enqueue_style( 'foto-fonts', 'http://fonts.googleapis.com/css?family=Lato:400,700,400italic|Oswald:300', '', '1.0', 'all' );
  65. wp_enqueue_style( 'foto-style', get_stylesheet_uri(), false, '1.2', 'all' );
  66. wp_enqueue_script( 'jquery' );
  67. if ( is_singular() && wp_attachment_is_image( $post->ID ) ) {
  68. wp_enqueue_script( 'foto-keyboard-image-navigation', get_template_directory_uri() . '/js/vendor/keyboard-image-navigation.js', array( 'jquery' ), '1.0' );
  69. }
  70. wp_enqueue_script( 'foto-plugins', get_template_directory_uri() . '/js/plugins.js', array( 'jquery' ), '1.0', true );
  71. wp_enqueue_script( 'foto-methods', get_template_directory_uri() . '/js/methods.js', array( 'jquery' ), '1.0', true );
  72. }
  73. /**
  74. * Deregister default wp-pagenavi style
  75. *
  76. * @since 0.0.1
  77. */
  78. function foto_deregister_styles() {
  79. wp_deregister_style( 'wp-pagenavi' );
  80. }
  81. /**
  82. * Comment reply js
  83. *
  84. * @since 0.0.4
  85. */
  86. function foto_enqueue_comment_reply_script() {
  87. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  88. wp_enqueue_script( 'comment-reply' );
  89. }
  90. }
  91. /**
  92. * Redirect to the Dashboard Page when after user activated the theme.
  93. *
  94. * @since 1.1
  95. */
  96. global $pagenow;
  97. if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' ) {
  98. wp_redirect( admin_url( 'themes.php?page=options-framework' ) );
  99. exit;
  100. }
  101. /**
  102. * Creates a nicely formatted and more specific title element text
  103. * for output in head of document, based on current view.
  104. *
  105. * @since 1.1
  106. */
  107. function foto_title( $title, $sep ) {
  108. global $paged, $page;
  109. if ( is_feed() )
  110. return $title;
  111. // Add the site name.
  112. $title .= get_bloginfo( 'name' );
  113. // Add the site description for the home/front page.
  114. $site_description = get_bloginfo( 'description', 'display' );
  115. if ( $site_description && ( is_home() || is_front_page() ) )
  116. $title = "$title $sep $site_description";
  117. // Add a page number if necessary.
  118. if ( $paged >= 2 || $page >= 2 )
  119. $title = "$title $sep " . sprintf( __( 'Page %s', 'foto' ), max( $paged, $page ) );
  120. return $title;
  121. }
  122. /**
  123. * Adds custom classes to the array of body classes.
  124. *
  125. * @since 0.0.1
  126. */
  127. function foto_body_classes( $classes ) {
  128. // Adds a class of group-blog & multi-author to blogs with more than 1 published author
  129. if ( is_multi_author() ) {
  130. $classes[] = 'multi-author';
  131. }
  132. return $classes;
  133. }
  134. /**
  135. * Add a twitter contact info
  136. *
  137. * @since 0.0.1
  138. */
  139. function foto_new_contactmethods( $contactmethods ) {
  140. $contactmethods['twitter'] = 'Twitter'; // Add Twitter
  141. return $contactmethods;
  142. }
  143. /**
  144. * Customize tag cloud widget
  145. *
  146. * @since 0.0.1
  147. */
  148. function foto_new_tag_cloud( $args ) {
  149. $args['largest'] = 12;
  150. $args['smallest'] = 12;
  151. $args['unit'] = 'px';
  152. return $args;
  153. }
  154. /**
  155. * Filter in a link to a content ID attribute for the next/previous image links on image attachment pages
  156. *
  157. * @since 0.0.2
  158. */
  159. function foto_enhanced_image_navigation( $url, $id ) {
  160. if ( ! is_attachment() && ! wp_attachment_is_image( $id ) )
  161. return $url;
  162. $image = get_post( $id );
  163. if ( ! empty( $image->post_parent ) && $image->post_parent != $id )
  164. $url .= '#main';
  165. return $url;
  166. }
  167. /**
  168. * Register our sidebars and widgetized areas
  169. *
  170. * @since 0.0.1
  171. */
  172. function foto_widgets_init() {
  173. register_widget( 'foto_author_bio' );
  174. register_sidebar(array(
  175. 'name' => __( 'Home Widget', 'foto'),
  176. 'description' => __( 'This sidebar appears on the right side of your site on home page', 'foto' ),
  177. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  178. 'after_widget' => '</section>',
  179. 'before_title' => '<div class="widget-title">',
  180. 'after_title' => '</div>',
  181. ));
  182. register_sidebar(array(
  183. 'name' => __( 'Footer Left Widget', 'foto'),
  184. 'description' => __( 'This sidebar appears on the footer of your site', 'foto' ),
  185. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  186. 'after_widget' => '</section>',
  187. 'before_title' => '<div class="widget-title">',
  188. 'after_title' => '</div>',
  189. ));
  190. register_sidebar(array(
  191. 'name' => __( 'Footer Center Widget', 'foto'),
  192. 'description' => __('This sidebar appears on the footer of your site', 'foto'),
  193. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  194. 'after_widget' => '</section>',
  195. 'before_title' => '<div class="widget-title">',
  196. 'after_title' => '</div>',
  197. ));
  198. register_sidebar(array(
  199. 'name' => __( 'Footer Right Widget', 'foto'),
  200. 'description' => __('This sidebar appears on the footer of your site', 'foto'),
  201. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  202. 'after_widget' => '</section>',
  203. 'before_title' => '<div class="widget-title">',
  204. 'after_title' => '</div>',
  205. ));
  206. register_sidebar(array(
  207. 'name' => __( 'Page Widget', 'foto'),
  208. 'description' => __('This sidebar appears on the footer of your site', 'foto'),
  209. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  210. 'after_widget' => '</section>',
  211. 'before_title' => '<div class="widget-title">',
  212. 'after_title' => '</div>',
  213. ));
  214. }
  215. ?>