Advertisement
deliciousthemes

Haze - New shortcode functions

May 10th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.23 KB | None | 0 0
  1. <?php
  2.  
  3. /*-----------------------------------------------------------------------------------*/
  4. /*  Widgets
  5. /*-----------------------------------------------------------------------------------*/
  6.  
  7. function my_widget_shortcode( $atts ) {
  8.  
  9. // Configure defaults and extract the attributes into variables
  10. extract( shortcode_atts(
  11.     array(
  12.         'name'  => '',
  13.         'instance' => '',
  14.     ),
  15.     $atts
  16. ));
  17.  
  18. $instance = str_ireplace("&amp;", '&' ,$instance);
  19.  
  20. $args = array(
  21.     'before_widget' => '<div class="page-widget">',
  22.     'after_widget'  => '</div>',
  23.     'before_title'  => '<h3>',
  24.     'after_title'   => '</h3>',
  25. );
  26.  
  27. ob_start();
  28. the_widget( $name, $instance, $args );
  29. $output = ob_get_clean();
  30.  
  31. return $output;
  32.  
  33. }
  34.  
  35. add_shortcode( 'widget', 'my_widget_shortcode' );
  36.  
  37.  
  38.  
  39. /*-----------------------------------------------------------------------------------*/
  40. /*  Buttons
  41. /*-----------------------------------------------------------------------------------*/
  42. function button_shortcode( $atts, $content = null )
  43. {
  44.     extract( shortcode_atts( array(
  45.       'color' => 'white',
  46.       'text' => '',
  47.       'url' => '',
  48.       ), $atts ) );
  49.        
  50.     if($url) {
  51.       return '<a class="button ' . $color . '" href="' . $url . '">' . $text . $content . '</a>';
  52.     } else {
  53.         return '<a class="button ' . $color . '" href="">' . $text . $content . '</a>';
  54.     }
  55. }
  56.  
  57. add_shortcode('button', 'button_shortcode');
  58.  
  59.  
  60.  
  61. /*-----------------------------------------------------------------------------------*/
  62. /*  Clear
  63. /*-----------------------------------------------------------------------------------*/
  64. function clear_shortcode() {
  65.    return '<div class="clear"></div>';
  66. }
  67.  
  68. add_shortcode( 'clear', 'clear_shortcode' );
  69.  
  70.  
  71.  
  72. /*-----------------------------------------------------------------------------------*/
  73. /*  Separator
  74. /*-----------------------------------------------------------------------------------*/
  75. function separator_shortcode() {
  76.    return '<div class="separator"></div>';
  77. }
  78.  
  79. add_shortcode( 'separator', 'separator_shortcode' );
  80.  
  81.  
  82.  
  83. /*-----------------------------------------------------------------------------------*/
  84. /*  Space
  85. /*-----------------------------------------------------------------------------------*/
  86. function space_shortcode() {
  87.    return '<div class="space"></div>';
  88. }
  89.  
  90. add_shortcode( 'space', 'space_shortcode' );
  91.  
  92.  
  93.  
  94. /*-----------------------------------------------------------------------------------*/
  95. /*  Line Break
  96. /*-----------------------------------------------------------------------------------*/
  97. function line_break_shortcode() {
  98. return '<br />';
  99. }
  100. add_shortcode( 'br', 'line_break_shortcode' );
  101.  
  102.  
  103.  
  104. /*-----------------------------------------------------------------------------------*/
  105. /*  Info Boxes
  106. /*-----------------------------------------------------------------------------------*/
  107. function box_shortcode( $atts, $content = null )
  108. {
  109.     extract( shortcode_atts( array(
  110.         'type' => 'error',
  111.         'text' => ''
  112.     ), $atts ) );
  113.      
  114.     return '<div class="box-' . $type . '"> ' . $text . $content .'</div>';
  115. }
  116.  
  117. add_shortcode('box', 'box_shortcode');
  118.  
  119.  
  120.  
  121. /*-----------------------------------------------------------------------------------*/
  122. /*  Lists
  123. /*-----------------------------------------------------------------------------------*/
  124. function list_shortcode( $atts, $content = null )
  125. {
  126.     extract( shortcode_atts( array(
  127.         'style' => 'tick',
  128.         'text' => ''
  129.     ), $atts ) );
  130.      
  131.     return '<ul class="customlist ' . $style . '-list"> ' . $text . $content .'</ul>';
  132. }
  133.  
  134. add_shortcode('list', 'list_shortcode');
  135.  
  136.  
  137.  
  138. /*-----------------------------------------------------------------------------------*/
  139. /*  Dropcaps
  140. /*-----------------------------------------------------------------------------------*/
  141. function dropcap_shortcode( $atts, $content = null )
  142. {
  143.     extract( shortcode_atts( array(
  144.         'style' => '1',
  145.         'text' => ''
  146.     ), $atts ) );
  147.      
  148.     return '<span class="dropcap' . $style . '">' . $text . $content .'</span>';
  149. }
  150.  
  151. add_shortcode('dropcap', 'dropcap_shortcode');
  152.  
  153.  
  154.  
  155. /*-----------------------------------------------------------------------------------*/
  156. /*  Highlighted text
  157. /*-----------------------------------------------------------------------------------*/
  158. function highlighted_shortcode( $atts, $content = null )
  159. {
  160.     extract( shortcode_atts( array(
  161.         'color' => 'dark',
  162.         'text' => ''
  163.     ), $atts ) );
  164.      
  165.     return '<span class="highlight ' . $color . '">' . $text . $content .'</span>';
  166. }
  167.  
  168. add_shortcode('highlighted', 'highlighted_shortcode');
  169.  
  170.  
  171.  
  172. /*-----------------------------------------------------------------------------------*/
  173. /*  Contact Form Wrapper
  174. /*-----------------------------------------------------------------------------------*/
  175. function contact_wrapper_shortcode( $atts, $content = null )
  176. {
  177.     extract( shortcode_atts( array(
  178.         'class' => ''
  179.     ), $atts ) );
  180.      
  181.     return '<div class="contactform '.$class.'">'.do_shortcode($content).'</div>';
  182. }
  183.  
  184. add_shortcode('form-wrapper', 'contact_wrapper_shortcode');
  185.  
  186.  
  187.  
  188. /*-----------------------------------------------------------------------------------*/
  189. /*  Columns
  190. /*-----------------------------------------------------------------------------------*/
  191. function column_shortcode( $atts, $content = null )
  192. {
  193.     extract( shortcode_atts( array(
  194.         'size' => 'one-half',
  195.         'text' => '',
  196.         'position' => ''
  197.     ), $atts ) );
  198.  
  199.     if(!empty($position)) {
  200.         return '<div class="percent-' . $size . ' column-' . $position . '"> '.do_shortcode($content).'</div>';
  201.     } else {
  202.         return '<div class="percent-' . $size . '"> ' .do_shortcode($content). '</div>';
  203.     }
  204. }
  205.  
  206. add_shortcode('column', 'column_shortcode');
  207.  
  208.  
  209.  
  210. /*-----------------------------------------------------------------------------------*/
  211. /*  Togggles
  212. /*-----------------------------------------------------------------------------------*/
  213. function toggle_shortcode( $atts, $content = null )
  214. {
  215.     extract( shortcode_atts(
  216.     array(
  217.         'title' => 'Toggle 1'
  218.     ),  $atts ) );
  219.  
  220.         return '<ul class="toggle-view"><li><span class="toggle-plus"></span><div></div><h3>'. $title .'</h3><div class="panel">' . do_shortcode($content) . '</div></li></ul>';
  221. }
  222.  
  223. add_shortcode('toggle', 'toggle_shortcode');
  224.  
  225.  
  226.  
  227. /*-----------------------------------------------------------------------------------*/
  228. /*  Accordion
  229. /*-----------------------------------------------------------------------------------*/
  230. function accordion_shortcode( $atts, $content = null )
  231. {
  232.     extract( shortcode_atts(
  233.     array(
  234.         'title' => 'Accordion 1'
  235.     ),  $atts ) );
  236.  
  237.         return '<div class="accordion"><div class="ac-btn"><h3>'. $title .'</h3></div><div class="ac-content">' . do_shortcode($content) . '</div></div>';
  238. }
  239.  
  240. add_shortcode('accordion', 'accordion_shortcode');
  241.  
  242.  
  243.  
  244. /*-----------------------------------------------------------------------------------*/
  245. /*  Tabs
  246. /*-----------------------------------------------------------------------------------*/
  247. function delicious_tab_group( $atts, $content ){
  248.     $GLOBALS['tab_count'] = 0;
  249.  
  250.     do_shortcode( $content );
  251.  
  252.     if(!isset($GLOBALS['tabs'])) {
  253.         $GLOBALS['tabs'] = "Assigned";
  254.     }
  255.  
  256.     $return ="";
  257.  
  258.     if( is_array( $GLOBALS['tabs'] ) ){
  259.         $i=1;
  260.         foreach( $GLOBALS['tabs'] as $tab ){
  261.             $tabs[] = '<li><a class="" href="#tab'. $i .'">'.$tab['title'].'</a></li>';
  262.             $panes[] = '<div id="tab'. $i .'" class="tab-content">'.$tab['content'].'</div>';
  263.             $i++;
  264.         }
  265.  
  266.         $return = "\n".'<div class="tabs-wrapper"><ul class="tabs">'.implode( "\n", $tabs ).'</ul>'."\n".'<div class="tabs-container">'.implode( "\n", $panes ).'</div></div>'."\n";
  267.     }
  268.    
  269.     return $return;
  270. }
  271.  
  272. add_shortcode( 'tabgroup', 'delicious_tab_group' );
  273.  
  274.  
  275. function delicious_tab( $atts, $content ){
  276.     extract(shortcode_atts(array(
  277.         'title' => 'Tab %d'
  278.     ), $atts));
  279.  
  280.     $x = $GLOBALS['tab_count'];
  281.     $GLOBALS['tabs'][$x] = array( 'title' => sprintf( $title, $GLOBALS['tab_count'] ), 'content' =>  $content );
  282.  
  283.     $GLOBALS['tab_count']++;
  284. }
  285.  
  286. add_shortcode( 'tab', 'delicious_tab' );
  287.  
  288.  
  289.  
  290. /*-----------------------------------------------------------------------------------*/
  291. /*  Pricing Table
  292. /*-----------------------------------------------------------------------------------*/
  293. function delicious_pricing_table( $atts, $content = null ) {
  294.     global $dt_table;
  295.     extract(shortcode_atts(array(
  296.         'columns' => '5'
  297.     ), $atts));
  298.    
  299.     $columnsNr = '';
  300.  
  301.     switch ($columns) {
  302.         case '2':
  303.             $columnsNr .= 'table-2';
  304.             break;
  305.         case '3':
  306.             $columnsNr .= 'table-3';
  307.             break;
  308.         case '4':
  309.             $columnsNr .= 'table-4';
  310.             break;
  311.         case '5':
  312.             $columnsNr .= 'table-5';
  313.             break;
  314.         case '6':
  315.             $columnsNr .= 'table-6';
  316.             break;
  317.     }
  318.  
  319.     do_shortcode($content);
  320.  
  321.     $columnContent = '';
  322.     $noBorder = '';
  323.     if (is_array($dt_table)) {
  324.  
  325.         for ($i = 0; $i < count($dt_table); $i++) {
  326.             $columnClass = 'column'; $n = $i + 1;
  327.             $columnClass .= ( $n % 2 ) ?  '' : ' even-column';
  328.             $columnClass .= ( $n == count($dt_table) ) ?  ' last-column' : '';
  329.             $columnClass .= ( $n == 1 ) ?  ' first-column' : '';
  330.             $noBorder .= 'no-border' ;
  331.  
  332.             $columnContent .= '<li class="'.$columnClass.' '.$columnsNr.'">';
  333.             if ((empty($dt_table[$i]['title'])) || (empty($dt_table[$i]['price'])) || ($dt_table[$i]['title'] == '') || ($dt_table[$i]['price'] == '') ) {
  334.             $columnContent .= '<div class="column-header '.$noBorder.'"><h3>'.$dt_table[$i]['title'].'</h3><span>'.$dt_table[$i]['price'].'</span></div>'; }
  335.             else {
  336.             $columnContent .= '<div class="column-header"><h3>'.$dt_table[$i]['title'].'</h3><span>'.$dt_table[$i]['price'].'</span></div>'; }
  337.             $columnContent .= '<div class="column-body">'.str_replace(array("\r\n", "\n", "\r", "<p></p>"), array("", "", "", ""), $dt_table[$i]['content']).'</div>';
  338.             $columnContent .= '</li>';
  339.         }
  340.        
  341.         $finished_table = '<ul class="pricing-table">'.$columnContent.'</ul>';
  342.     }
  343.    
  344.     $dt_table = '';
  345.    
  346.     return $finished_table;
  347.    
  348. }
  349.  
  350. add_shortcode('pricing-table', 'delicious_pricing_table');
  351.  
  352.  
  353. // Single Column
  354. function shortcode_pricing_column( $atts, $content = null ) {
  355.     global $dt_table;
  356.     extract(shortcode_atts(array(
  357.         'title' => '',
  358.         'price' => ''
  359.     ), $atts));
  360.    
  361.     $column['title'] = $title;
  362.     $column['price'] = $price;
  363.     $column['content'] = do_shortcode($content);
  364.    
  365.     $dt_table[] = $column;
  366.    
  367. }
  368.  
  369. add_shortcode('pricing-column', 'shortcode_pricing_column');
  370.  
  371.  
  372.  
  373. /*-----------------------------------------------------------------------------------*/
  374. /*  Cross Button for Pricing Table
  375. /*-----------------------------------------------------------------------------------*/
  376. function cross_shortcode() {
  377.    return '<img src="'.get_template_directory_uri().'/images/cross-button.png" alt="" />';
  378. }
  379.  
  380. add_shortcode( 'cross', 'cross_shortcode' );
  381.  
  382.  
  383.  
  384. /*-----------------------------------------------------------------------------------*/
  385. /*  Tick Button for Pricing Table
  386. /*-----------------------------------------------------------------------------------*/
  387. function tick_shortcode() {
  388.    return '<img src="'.get_template_directory_uri().'/images/tick-button.png" alt="" />';
  389. }
  390.  
  391. add_shortcode( 'tick', 'tick_shortcode' );
  392.  
  393.  
  394.  
  395. /*-----------------------------------------------------------------------------------*/
  396. /*  Google Map
  397. /*-----------------------------------------------------------------------------------*/
  398. function delicious_googlemap($atts, $content = null) {
  399.     extract(shortcode_atts(array(
  400.         "width" => '940',
  401.         "height" => '300',
  402.         "src" => ''
  403.     ), $atts));
  404.    
  405.    return '<div class="contact-map"><iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$src.'&amp;output=embed"></iframe></div>';
  406. }
  407.  
  408. add_shortcode("googlemap", "delicious_googlemap");
  409.  
  410.  
  411.  
  412. /*-----------------------------------------------------------------------------------*/
  413. /*  Services Item
  414. /*-----------------------------------------------------------------------------------*/
  415. function delicious_services($atts, $content = null) {
  416.     extract(shortcode_atts(array(
  417.         "id" => ''
  418.     ), $atts));
  419.  
  420.     global $post;
  421.    
  422.     $args = array(
  423.         'post_type' => 'services',
  424.         'posts_per_page' => 1,
  425.         'p' => $id
  426.     );
  427.     $my_query = new WP_Query($args);
  428.     if( $my_query->have_posts() ) :
  429.     while ($my_query->have_posts()) : $my_query->the_post();
  430.     $retour ='';
  431.     $s_items = get_post_meta( get_the_ID(), 'haze_service_item_align', false );        
  432.     if ( in_array( 'left', $s_items ) )
  433.         {
  434.         $retour .='<div class="service-item content-left">';
  435.         }
  436.         else
  437.         {
  438.             $retour .='<div class="service-item content-center">';
  439.         }      
  440.     $retour .= get_the_post_thumbnail( $id, 'service-thumb', array('class' => 'service-img') );
  441.     $retour .='<h3 class="service">'.get_the_title().'</h3>';
  442.     $retour .='<p class="clear">'.get_the_content().'</p>';
  443.     $retour .='</div>';
  444.  
  445.     endwhile; else:
  446.     $retour ='';
  447.     $retour .= "nothing found.";
  448.     endif;
  449.  
  450.     //Reset Query
  451.     wp_reset_query();
  452.    
  453.     return $retour;
  454. }
  455.  
  456. add_shortcode("service", "delicious_services");
  457.  
  458.  
  459.  
  460. /*-----------------------------------------------------------------------------------*/
  461. /*  Team Member
  462. /*-----------------------------------------------------------------------------------*/
  463. function delicious_member($atts, $content = null) {
  464.     extract(shortcode_atts(array(
  465.         "id" => ''
  466.     ), $atts));
  467.  
  468.     global $post;
  469.  
  470.     $args = array(
  471.         'post_type' => 'team',
  472.         'posts_per_page' => 1,
  473.         'p' => $id
  474.     );
  475.    
  476.     $team_query = new WP_Query($args);
  477.     if( $team_query->have_posts() ) :
  478.     while ($team_query->have_posts()) : $team_query->the_post();
  479.    
  480.     $position = get_post_meta($post->ID, 'haze_position', true);
  481.     $twitter = get_post_meta($post->ID, 'haze_twitter', true);
  482.     $facebook = get_post_meta($post->ID, 'haze_facebook', true);
  483.     $linkedin = get_post_meta($post->ID, 'haze_linkedin', true);
  484.    
  485.     $retour ='';
  486.     $retour .='<div class="team-member">';
  487.         $retour .='<div class="team-details">';
  488.             $retour .= get_the_post_thumbnail( $id, 'member-thumb', array('class' => 'team-avatar') );
  489.             $retour .='<div class="team-social">';
  490.                 if(!empty($twitter)) {
  491.                 $retour .='<a class="team-twitter" href="'.$twitter.'"><img src="'. get_template_directory_uri() .'/images/team-twitter.png" alt="Twitter Page" /></a>'; }
  492.                 if(!empty($facebook)) {
  493.                 $retour .='<a class="team-facebook" href="'.$facebook.'"><img src="'. get_template_directory_uri() .'/images/team-facebook.png" alt="Facebook Profile" /></a>'; }
  494.                 if(!empty($linkedin)) {
  495.                 $retour .='<a class="team-linkedin" href="'.$linkedin.'"><img src="'. get_template_directory_uri() .'/images/team-linkedin.png" alt="Linkedin Profile" /></a>'; }
  496.             $retour .='</div>';
  497.         $retour .='</div>';
  498.         $retour .='<div class="team-text">';
  499.             $retour .='<h3>';
  500.             $retour .= get_the_title();
  501.             if(!empty($position)) {
  502.             $retour .=' - <span>'.$position.'</span>'; }
  503.             $retour .='</h3>';
  504.         $retour .='</div>';
  505.         $retour .='<p>'.get_the_content().'</p>';
  506.     $retour .='</div>';
  507.  
  508.      endwhile; else:
  509.      $retour ='';
  510.      $retour .= "nothing found.";
  511.      endif;
  512.  
  513.     //Reset Query
  514.     wp_reset_query();
  515.    
  516.     return $retour;
  517. }
  518. add_shortcode("team-member", "delicious_member");
  519.  
  520.  
  521.  
  522. /*-----------------------------------------------------------------------------------*/
  523. /*  Shortcode Filter
  524. /*-----------------------------------------------------------------------------------*/
  525. add_filter('the_content', 'do_shortcode', 7);
  526.  
  527. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement