jrothra

KAR Site Functions.php

Jul 8th, 2015
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.41 KB | None | 0 0
  1. <?php
  2. //
  3. // Recommended way to include parent theme styles.
  4. //  (Please see http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme)
  5. //  
  6. add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
  7. function theme_enqueue_styles() {
  8.     wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
  9.     wp_enqueue_style( 'child-style',
  10.         get_stylesheet_directory_uri() . '/style.css',
  11.         array('parent-style')
  12.     );
  13. }
  14. //
  15. // Your code goes below
  16. //
  17. function add_custom_sections ( $args ) {
  18.     //set up global vars with the section parameters
  19.     global $section_params;
  20.     $defaults = array(
  21.         'ids'           => array( ) ,
  22.         'hook'          => '__after_main_wrapper' ,
  23.         'priority'      => 0,
  24.         'layout'        => 'full',
  25.         'context'       => 'home',
  26.         'blur'          => true,
  27.         'apply_shadow'      => true,
  28.         'background'        => 'thumb'
  29.     );
  30.  
  31.     $section_params = wp_parse_args( $args, $defaults );
  32.    
  33.     //sets up hooks
  34.     add_action ( 'wp_head' , '_hook_setup' );
  35.     add_action('wp_head' , '_my_custom_sections_style');
  36. }
  37.  
  38. $my_sections_args = array(
  39.     'ids'           => array( 6 , 8 , 4 ),
  40.     'blur'          => 0,
  41.     'background'        => array( 6 => 'thumb' , 8 => "#0088cc", 4 => 'thumb' ),
  42.     'context'       => 'home',
  43.     'hook'          => '__before_main_wrapper',
  44.     'apply_shadow'      => false,
  45.     'layout'        => 'full',
  46. );
  47. add_custom_sections ( $my_sections_args );
  48.  
  49. function _hook_setup() {
  50.     //gets section(s) parameters
  51.     global $section_params;
  52.     extract( $section_params , EXTR_OVERWRITE );
  53.  
  54.     //check context
  55.     $context_type = is_numeric($context) ? 'post' : $context;
  56.     switch ( $context_type ) {
  57.         case 'post':
  58.             if ( $context != get_the_ID() )
  59.                 return;
  60.             break;
  61.        
  62.         default :
  63.             if ( ! tc__f('__is_home') )
  64.                 return;
  65.             break;
  66.     }
  67.     //sets up hook
  68.     add_action ( $hook , '_display_my_custom_sections' , $priority);
  69. }
  70.  
  71.  
  72. function _display_my_custom_sections() {
  73.     //gets section(s) parameters
  74.     global $section_params;
  75.     extract( $section_params , EXTR_OVERWRITE );
  76.  
  77.     //check if we have posts ids
  78.     if ( ! is_array($ids) || empty($ids) )
  79.         return;
  80.  
  81.     while ( $current_id = current($ids) ) {
  82.         $section_object = get_post($current_id);
  83.         if ( empty($section_object) ) {
  84.             next($ids);
  85.             continue;
  86.         }
  87.         ob_start()
  88.         ?>
  89.         <div class="row-fluid custom-section custom-section-<?php echo $current_id ?>">
  90.             <div class="custom-section-background"></div>
  91.             <div id="content span12" class="article-container">
  92.                 <article>
  93.                     <div class="entry-content">
  94.                         <?php echo apply_filters('the_content' , $section_object -> post_content ); ?>
  95.                     </div>
  96.                 </article>
  97.             </div>
  98.             <?php
  99.             //adds an edit link
  100.             $edit_enabled                      = ( (is_user_logged_in()) && current_user_can('edit_pages') && ( 'page' == $section_object -> post_type) ) ? true : false;
  101.             $edit_enabled                      = ( (is_user_logged_in()) && current_user_can('edit_post' , $current_id ) && ( 'page' != $section_object -> post_type ) ) ? true : $edit_enabled;
  102.             if ( $edit_enabled )
  103.                 printf('<a class="edit-link btn btn-inverse" href="%1$s" title="%2$s" target="_blank">%2$s</a>',
  104.                         get_edit_post_link($current_id),
  105.                         ( 'page' == $section_object -> post_type ) ? __( 'Edit page' , 'customizr' ) : __( 'Edit post' , 'customizr' )
  106.                 );
  107.             ?>
  108.         </div>
  109.         <?php
  110.         $html = ob_get_contents();
  111.         if ($html) ob_end_clean();
  112.         //wrap in a container if layout is not set to full
  113.         if ( 'full' != $layout )
  114.             printf('<div class="container boxed-section">%1$s</div>', $html);
  115.         else
  116.             echo $html;
  117.  
  118.         next($ids);
  119.     }//end while loop
  120. }
  121.  
  122. function _my_custom_sections_style() {
  123.     //gets section(s) parameters
  124.     global $section_params;
  125.     extract( $section_params , EXTR_OVERWRITE );
  126.     if ( ! is_array($ids) || empty($ids) )
  127.         return;
  128.     ?>
  129.     <style type="text/css" id="my-sections-style">
  130.         .custom-section {
  131.             position: relative;
  132.             -webkit-box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  133.             -moz-box-shadow: 0 2px 10px rgba(0,0,0,.25);
  134.             box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.25);
  135.         }
  136.         .custom-section .article-container {
  137.             position: relative;
  138.             z-index: 10;
  139.             padding: 20px;
  140.             color: white;
  141.             width: 90%;
  142.             padding: 5% 5%;
  143.             vertical-align: middle;
  144.             display: inline-block;
  145.             position: relative;
  146.         }
  147.         <?php if ($apply_shadow) : ?>
  148.         .custom-section .article-container {
  149.             background: rgba(0, 0, 0, 0.2);
  150.             filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#33000000', endColorstr='#33000000', GradientType=0);
  151.         }
  152.         <?php endif;?>
  153.         .full-width-section .custom-section .article-container {
  154.             padding: 0px;
  155.         }
  156.         .custom-section .edit-link.btn {
  157.             z-index: 100;
  158.             position: absolute;
  159.             bottom: 10px;
  160.             right: 10px;
  161.             right: 12px;
  162.             z-index: 100;
  163.             display: block;
  164.         }
  165.         .custom-section-background {
  166.             height: 100%;
  167.             position: absolute;
  168.             width: 100%;
  169.             z-index: 0;
  170.         }
  171.         <?php if ( false != $blur) : ?>
  172.             <?php $blur = !is_numeric($blur) ? 4 : $blur; ?>
  173.             .custom-section-background {
  174.                 -webkit-filter: blur(<?php echo $blur; ?>px);
  175.                 -moz-filter: blur(<?php echo $blur; ?>px);
  176.                 -o-filter: blur(<?php echo $blur; ?>px);
  177.                 -ms-filter: blur(<?php echo $blur; ?>px);
  178.                 filter: blur(<?php echo $blur; ?>px);
  179.             }
  180.         <?php endif; ?>
  181.         <?php
  182.             $i = 4;
  183.             foreach ($ids as $key => $post_id) {
  184.                 if ( ! _set_section_background( $background, $post_id, $i ) )
  185.                     continue;
  186.                 echo _set_section_background( $background, $post_id, $i );
  187.                 $i = ($i < 10 ) ? $i+1 : 1;
  188.             }//end for each
  189.         ?>
  190.     </style>
  191.     <?php
  192. }
  193.  
  194. function _set_section_background($background, $post_id, $i) {
  195.     if ( 'none' == $background
  196.         || ( is_array($background)
  197.             && isset($background[$post_id])
  198.             && 'none' == $background[$post_id] )
  199.         )
  200.         return false;
  201.  
  202.     if ( 'randcolors' == $background
  203.         || ( is_array($background)
  204.             && isset($background[$post_id])
  205.             && $background[$post_id] == 'randcolors' )
  206.         ) {
  207.         //random colors
  208.         $rand_color_key         = '';
  209.  
  210.         $colors             = array("#510300" , "#4D2A33", "#2B3F38", "#03A678" ,"#7A5945" , "#807D77" ,"#073233", "#B3858A","#F57B3D", "#449BB5", "#043D5D", "#EB5055", "#68C39F", "#1A4A72", "#4B77BE", "#5C97BF", "#F5AE30", "#EDA737", "#C8C8C8", "#13181C", "#248F79", "#D95448", "#26B89A" , "#EC6766", "#E74C3C");
  211.         $rand_color_key     = array_rand($colors, 1);
  212.         return sprintf('.custom-section-%1$s .custom-section-background {background-color:%2$s;opacity: 0.7;}',
  213.             $post_id,
  214.             $colors[$rand_color_key]
  215.         );
  216.     }//end if random colors
  217.  
  218.  
  219.     //if background is a color or an associative array of post_id => color
  220.     if ( ! is_array($background) && false !== strpos($background, '#')
  221.         || ( is_array($background)
  222.         && isset($background[$post_id])
  223.         && false !== strpos($background[$post_id], '#') )
  224.         ) {
  225.         return sprintf('.custom-section-%1$s .custom-section-background {background-color:%2$s;opacity: 0.7;}',
  226.             $post_id,
  227.             is_array($background) ? $background[$post_id] : $background
  228.         );
  229.     } // end if color defined
  230.  
  231.     $is_rand_image = ( 'randimages' == $background
  232.         ||  ( is_array($background)
  233.             && isset($background[$post_id])
  234.             && $background[$post_id] == 'randimages' )
  235.         ) ? true : false;
  236.     $attachment_id  = has_post_thumbnail($post_id) ? get_post_thumbnail_id( $post_id ) : false ;
  237.     $thumb_src      = 'http://lorempixel.com/g/900/500/city/' .$i ;
  238.     $thumb_src      = ( ! $is_rand_image && false != $attachment_id ) ? wp_get_attachment_image_src( $attachment_id, 'large', false ) : $thumb_src;
  239.     $thumb_src      = is_array($thumb_src) ? $thumb_src[0] : $thumb_src;
  240.     return sprintf('.custom-section-%1$s .custom-section-background {background: url("%2$s") no-repeat center center fixed;-webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; }',
  241.         $post_id,
  242.         $thumb_src
  243.     );
  244. }//end of _set_section_background
  245.  
  246. //Customized Footer Copyright Credits
  247. add_filter('tc_credits_display', 'my_custom_credits');
  248. function my_custom_credits(){
  249. $credits = '';
  250. $newline_credits = '';
  251. return '
  252. <div class="span4 credits">
  253.                     <p> &middot; &copy; '.esc_attr( date( 'Y' ) ).' <a href="'.esc_url( home_url() ).'" title="'.esc_attr(get_bloginfo()).'" rel="bookmark">'.esc_attr('Dr. Keith Rothra').'</a> &middot; '.($credits ? $credits : 'Customized by <a href="http://www.johnrothra.com/" target="_blank">John Rothra</a>').' &middot;'.($newline_credits ? '<br />&middot; '.$newline_credits.' &middot;' : '').'</p>     </div>';
  254. }
  255.  
  256. //Customized Post Meta Author Info
  257. add_filter( 'tc_post_tax_metas_html', 'my_tax_metas_html', 20, 2);
  258. function my_tax_metas_html( $html, $_tax = array() ){
  259.   if ( empty($_tax) )
  260.     return $_html;
  261.   //extract "_show_cats" , "_show_tags" , "cat_list", "tag_list"
  262.   extract($_tax);
  263.   $cat_list = ! empty($cat_list) && $_show_cats ? sprintf( '<br />%s %s' , 'Category:' , $cat_list ) : '';
  264.   $tag_list = ! empty($tag_list) && $_show_tags ? sprintf( '%s %s %s' , ! empty( $cat_list) ? ' |' : '', 'Tags: ' , $tag_list ) : '';
  265.   return sprintf( '%s%s' , $cat_list, $tag_list );
  266. }
  267. add_filter( 'tc_set_metas_content', 'my_metas_content', 20, 2);
  268. function my_metas_content( $_html, $_parts){
  269.   if ( empty($_parts) )
  270.     return $_html;
  271.  
  272.   //extract $_tax_text , $_date_text, $_author_text, $_update_text
  273.   extract($_parts);
  274.  
  275.   return sprintf( '%3$s %1$s %2$s %4$s' , $_date_text, $_tax_text , $_author_text, $_update_text );
  276. }
Advertisement
Add Comment
Please, Sign In to add comment