Guest User

Lifestyle functions.php

a guest
Jun 3rd, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.66 KB | None | 0 0
  1. <?php
  2. /**
  3. * Lifestyle functions and definitions
  4. *
  5. * @package Lifestyle
  6. */
  7.  
  8. function lifestyle_setup() {
  9.  
  10. remove_action( 'omega_before_header', 'omega_get_primary_menu' );
  11. add_action( 'omega_after_header', 'omega_get_primary_menu' );
  12.  
  13. add_theme_support( 'plugin-activation' );
  14.  
  15. /* Add support for a custom header image. */
  16. add_theme_support(
  17. 'custom-header',
  18. array( 'header-text' => false,
  19. 'flex-width' => true,
  20. 'uploads' => true,
  21. 'default-image' => get_stylesheet_directory_uri() . '/images/header.jpg'
  22. ));
  23.  
  24.  
  25.  
  26. add_theme_support( 'color-palette', array( 'callback' => 'lifestyle_register_colors' ) );
  27.  
  28. add_filter( 'loop_pagination_args', 'lifestyle_loop_pagination_args' );
  29.  
  30. remove_action( 'omega_home_before_entry', 'omega_entry_header' );
  31.  
  32. add_action( 'omega_after_header', 'lifestyle_banner' );
  33.  
  34. add_action('init', 'lifestyle_init', 1);
  35.  
  36. add_theme_support( 'omega-footer-widgets', 3 );
  37.  
  38. add_action( 'widgets_init', 'lifestyle_widgets_init', 15 );
  39.  
  40. }
  41.  
  42. add_action( 'after_setup_theme', 'lifestyle_setup', 11 );
  43.  
  44. function lifestyle_loop_pagination_args( $args ) {
  45. /* Set up some default arguments for the paginate_links() function. */
  46. $args = array(
  47. 'end_size' => 5,
  48. 'mid_size' => 4
  49. );
  50. return $args;
  51. }
  52.  
  53. /**
  54. * Register widgetized area and update sidebar with default widgets
  55. */
  56. function lifestyle_widgets_init() {
  57. register_sidebar( array(
  58. 'name' => __( 'Home Banner', 'lifestyle' ),
  59. 'id' => 'banner',
  60. 'description' => 'This widget area will replace the homepage header image',
  61. 'before_widget' => '<section id="%1$s" class="widget %2$s"><div class="widget-wrap">',
  62. 'after_widget' => '</div></section>',
  63. 'before_title' => '<h3 class="widget-title">',
  64. 'after_title' => '</h3>',
  65. ) );
  66.  
  67. }
  68.  
  69. function lifestyle_get_home_banner() {
  70. if ( is_active_sidebar( 'banner' ) ) {
  71. dynamic_sidebar( 'banner' );
  72. } else {
  73. echo '<img class="header-image" src="' . esc_url( get_header_image() ) . '" alt="' . esc_attr( get_bloginfo( 'description' ) ) . '" />';
  74. }
  75. }
  76.  
  77. function lifestyle_get_header_image() {
  78. if (get_header_image() && is_front_page()) {
  79. if ( is_active_sidebar( 'banner' ) ) {
  80. dynamic_sidebar( 'banner' );
  81. } else {
  82. if (get_theme_mod( 'lifestyle_header_link' )) {
  83. echo '<a href="'. esc_url( get_theme_mod( 'lifestyle_header_link' ) ) .'"><img class="header-image" src="' . esc_url( get_header_image() ) . '" alt="' . esc_attr( get_bloginfo( 'description' ) ) . '" /></a>';
  84. } else {
  85. echo '<img class="header-image" src="' . esc_url( get_header_image() ) . '" alt="' . esc_attr( get_bloginfo( 'description' ) ) . '" />';
  86. }
  87. }
  88. }
  89. }
  90.  
  91. function lifestyle_banner() {
  92.  
  93. ?>
  94. <div class="banner">
  95. <div class="wrap">
  96. <?php
  97. if(is_front_page()) {
  98. lifestyle_get_home_banner();
  99. } elseif ( !is_front_page() && get_theme_mod( 'lifestyle_header_home' ) ) {
  100. echo '';
  101. } else {
  102. // get title
  103. $id = get_option('page_for_posts');
  104.  
  105. if (( 'posts' == get_option( 'show_on_front' )) && (is_day() || is_month() || is_year() || is_tag() || is_category() || is_singular('post' ) || is_home())) {
  106. lifestyle_get_home_banner();
  107. } elseif(is_home() || is_singular('post' ) ) {
  108. if ( has_post_thumbnail($id) ) {
  109. echo get_the_post_thumbnail( $id, 'full' );
  110. }
  111. } elseif ( has_post_thumbnail() && is_singular('page' ) ) {
  112. the_post_thumbnail();
  113. }
  114. }
  115. ?>
  116. </div><!-- .wrap -->
  117. </div><!-- .banner -->
  118. <?php
  119. }
  120.  
  121. /**
  122. * Registers colors for the Color Palette extension.
  123. *
  124. * @since 0.1.0
  125. * @access public
  126. * @param object $color_palette
  127. * @return void
  128. */
  129.  
  130. function lifestyle_register_colors( $color_palette ) {
  131.  
  132. /* Add custom colors. */
  133. $color_palette->add_color(
  134. array( 'id' => 'primary', 'label' => __( 'Primary Color', 'lifestyle' ), 'default' => '232323' )
  135. );
  136. $color_palette->add_color(
  137. array( 'id' => 'link', 'label' => __( 'Link Color', 'lifestyle' ), 'default' => '858585' )
  138. );
  139.  
  140. /* Add rule sets for colors. */
  141.  
  142. $color_palette->add_rule_set(
  143. 'primary',
  144. array(
  145. 'color' => 'h1.site-title a, .site-description, .entry-meta',
  146. 'background-color' => '.tinynav, input[type="button"], input[type="reset"], input[type="submit"]'
  147. )
  148. );
  149. $color_palette->add_rule_set(
  150. 'link',
  151. array(
  152. 'color' => '.site-inner .entry-meta a, .site-inner .entry-content a, .site-inner .sidebar a'
  153. )
  154. );
  155. }
  156.  
  157. function lifestyle_init() {
  158. if(!is_admin()){
  159. wp_enqueue_script("tinynav", get_stylesheet_directory_uri() . '/js/tinynav.js', array('jquery'));
  160. }
  161. }
  162.  
  163. add_action( 'tgmpa_register', 'lifestyle_register_plugins' );
  164. /**
  165. * Register the required plugins for this theme.
  166. *
  167. * In this example, we register two plugins - one included with the TGMPA library
  168. * and one from the .org repo.
  169. *
  170. * The variable passed to tgmpa_register_plugins() should be an array of plugin
  171. * arrays.
  172. *
  173. * This function is hooked into tgmpa_init, which is fired within the
  174. * TGM_Plugin_Activation class constructor.
  175. */
  176. function lifestyle_register_plugins() {
  177.  
  178. /**
  179. * Array of plugin arrays. Required keys are name and slug.
  180. * If the source is NOT from the .org repo, then source is also required.
  181. */
  182. $plugins = array(
  183.  
  184. // This is an example of how to include a plugin from the WordPress Plugin Repository
  185. array(
  186. 'name' => 'Master Slider - Responsive Touch Slider',
  187. 'slug' => 'master-slider',
  188. 'required' => false,
  189. ),
  190.  
  191. );
  192.  
  193. /**
  194. * Array of configuration settings. Amend each line as needed.
  195. * If you want the default strings to be available under your own theme domain,
  196. * leave the strings uncommented.
  197. * Some of the strings are added into a sprintf, so see the comments at the
  198. * end of each line for what each argument will be.
  199. */
  200. $config = array(
  201. 'id' => 'omega', // Unique ID for hashing notices for multiple instances of TGMPA.
  202. 'default_path' => '', // Default absolute path to bundled plugins.
  203. 'menu' => 'tgmpa-install-plugins', // Menu slug.
  204. 'has_notices' => true, // Show admin notices or not.
  205. 'dismissable' => true, // If false, a user cannot dismiss the nag message.
  206. 'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
  207. 'is_automatic' => false, // Automatically activate plugins after installation or not.
  208. 'message' => '', // Message to output right before the plugins table.
  209. );
  210.  
  211. if (function_exists('tgmpa')) {
  212. tgmpa( $plugins, $config );
  213. }
  214.  
  215. }
  216.  
  217. ?>
Advertisement
Add Comment
Please, Sign In to add comment