/includes/functions-layout.php

  1. <?php 
  2. /** 
  3. * Theme Layout 
  4. * 
  5. * Set for the theme structure and grid 
  6. * 
  7. * @package responsive_mobile 
  8. * @license license.txt 
  9. * @copyright 2014 CyberChimps Inc 
  10. * @since 0.0.1 
  11. * 
  12. * Please do not edit this file. This file is part of the responsive_mobile Framework and all modifications 
  13. * should be made in a child theme. 
  14. */ 
  15.  
  16. // If this file is called directly, abort. 
  17. if ( ! defined( 'WPINC' ) ) { 
  18. die; 
  19.  
  20. /** 
  21. * Get current layout 
  22. */ 
  23. function responsive_mobile_get_layout() { 
  24.  
  25. if ( is_404() ) { 
  26. return 'default'; 
  27.  
  28. $layout = ''; 
  29. $responsive_mobile_options = responsive_mobile_get_options(); 
  30. $valid_layouts = responsive_mobile_valid_layouts(); 
  31.  
  32. /** For singular pages, get post meta */ 
  33. if ( is_singular() ) { 
  34. global $post; 
  35. /** Static pages */ 
  36. if ( is_page() ) { 
  37. $page_template = get_page_template_slug( $post->ID ); 
  38.  
  39. /** If custom page template is default, use page template first */ 
  40. if ( in_array( $page_template, array( 'page-templates/blog.php', 'page-templates/blog-excerpt.php' ) ) ) { 
  41. if ( 'default' == $responsive_mobile_options['blog_posts_index_layout_default'] ) { 
  42. $layout = basename( $page_template, '.php'); 
  43. } else { 
  44. $layout = $responsive_mobile_options['blog_posts_index_layout_default']; 
  45.  
  46. } else { 
  47. // If page is set to default then display default layout 
  48. if ( '' == $page_template ) { 
  49. $layout = $responsive_mobile_options['static_page_layout_default']; 
  50. // Otherwise get the page template 
  51. else { 
  52. $layout = basename( $page_template, '.php'); 
  53.  
  54. } /** Single blog posts */ 
  55. elseif ( is_single() ) { 
  56. $layout_meta_value = ( false != get_post_meta( $post->ID, '_responsive_mobile_layout', true ) ? get_post_meta( $post->ID, '_responsive_mobile_layout', true ) : 'default' ); 
  57. $layout_meta = ( array_key_exists( $layout_meta_value, $valid_layouts ) ? $layout_meta_value : 'default' ); 
  58.  
  59. /** If post custom meta is set, use it */ 
  60. if ( 'default' != $layout_meta ) { 
  61. $layout = $layout_meta; 
  62. } /** Else, use the default */ 
  63. else { 
  64. $layout = $responsive_mobile_options['single_post_layout_default']; 
  65.  
  66. } else { 
  67. /** Posts index */ 
  68. if ( is_home() || is_archive() || is_search() ) { 
  69. $layout = $responsive_mobile_options['blog_posts_index_layout_default']; 
  70. } /** Fallback */ 
  71. else { 
  72. $layout = 'default'; 
  73.  
  74.  
  75. $layout = apply_filters( 'responsive_mobile_get_layout', $layout ); 
  76.  
  77. return esc_attr( $layout ); 
  78.  
  79. /** 
  80. * Add Layout Meta Box 
  81. * 
  82. * @link http://codex.wordpress.org/Function_Reference/_2 __() 
  83. * @link http://codex.wordpress.org/Function_Reference/add_meta_box add_meta_box() 
  84. */ 
  85. function responsive_mobile_add_layout_meta_box( $post ) { 
  86. global $post, $wp_meta_boxes; 
  87.  
  88. $context = apply_filters( 'responsive_mobile_layout_meta_box_context', 'side' ); // 'normal', 'side', 'advanced' 
  89. $priority = apply_filters( 'responsive_mobile_layout_meta_box_priority', 'default' ); // 'high', 'core', 'low', 'default' 
  90.  
  91. add_meta_box( 
  92. 'responsive_mobile_layout',  
  93. __( 'Layout', 'responsive-mobile' ),  
  94. 'responsive_mobile_layout_meta_box',  
  95. 'post',  
  96. $context,  
  97. $priority 
  98. ); 
  99. // Hook meta boxes into 'add_meta_boxes' 
  100. add_action( 'add_meta_boxes', 'responsive_mobile_add_layout_meta_box' ); 
  101.  
  102. /** 
  103. * Define Layout Meta Box 
  104. * 
  105. * Define the markup for the meta box 
  106. * for the "layout" post custom meta 
  107. * data. The metabox will consist of 
  108. * radio selection options for "default" 
  109. * and each defined, valid layout 
  110. * option for single blog posts or 
  111. * static pages, depending on the 
  112. * context. 
  113. * 
  114. * @uses responsive_mobile_get_option_parameters() Defined in \functions\options.php 
  115. * @uses checked() 
  116. * @uses get_post_custom() 
  117. */ 
  118. function responsive_mobile_layout_meta_box() { 
  119. global $post; 
  120. $custom = ( get_post_custom( $post->ID ) ? get_post_custom( $post->ID ) : false ); 
  121. $layout = ( isset( $custom['_responsive_mobile_layout'][0] ) ? $custom['_responsive_mobile_layout'][0] : 'default' ); 
  122. $valid_layouts = responsive_mobile_valid_layouts(); 
  123. ?> 
  124. <p> 
  125. <select name="_responsive_mobile_layout"> 
  126. <?php foreach( $valid_layouts as $slug => $name ) { ?> 
  127. <?php $selected = selected( $layout, $slug, false ); ?> 
  128. <option value="<?php echo $slug; ?>" <?php echo $selected; ?>><?php echo $name; ?></option> 
  129. <?php } ?> 
  130. </select> 
  131. </p> 
  132. <?php 
  133.  
  134. /** 
  135. * Validate, sanitize, and save post metadata. 
  136. * 
  137. * Validates the user-submitted post custom 
  138. * meta data, ensuring that the selected layout 
  139. * option is in the array of valid layout 
  140. * options; otherwise, it returns 'default'. 
  141. * 
  142. * @link http://codex.wordpress.org/Function_Reference/update_post_meta update_post_meta() 
  143. * 
  144. * @link http://php.net/manual/en/function.array-key-exists.php array_key_exists() 
  145. * 
  146. * @uses responsive_mobile_get_option_parameters() Defined in \functions\options.php 
  147. */ 
  148. function responsive_mobile_save_layout_post_metadata() { 
  149. global $post; 
  150. if ( !isset( $post ) || !is_object( $post ) ) { 
  151. return; 
  152. $valid_layouts = responsive_mobile_valid_layouts(); 
  153. $layout = ( isset( $_POST['_responsive_mobile_layout'] ) && array_key_exists( $_POST['_responsive_mobile_layout'], $valid_layouts ) ? $_POST['_responsive_mobile_layout'] : 'default' ); 
  154.  
  155. update_post_meta( $post->ID, '_responsive_mobile_layout', $layout ); 
  156. add_action( 'save_post', 'responsive_mobile_save_layout_post_metadata' ); 
.