RUSSEL86

Shortcode collection

May 2nd, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.98 KB | None | 0 0
  1. <?php
  2.  
  3. function wishlist_shortcode($atts){
  4.     extract( shortcode_atts( array(
  5.         'cat' => '',
  6.     ), $atts, 'wishlist' ) );
  7.    
  8.     $q = new WP_Query(
  9.         array('posts_per_page' => '4', 'post_type' => 'wishlist-items', 'category_name' => $cat, 'meta_key' => 'order_number','orderby' => 'meta_value','order' => 'ASC')
  10.         );     
  11.        
  12.        
  13.     $list = '<div class="wishlist_item_list">';
  14.     while($q->have_posts()) : $q->the_post();
  15.         $idd = get_the_ID();
  16.         $wishlist_email = get_post_meta($idd, 'wishlist_email', true);
  17.         $featured_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'case-study-image' );
  18.         $theme_dir = get_bloginfo('template_directory');
  19.        
  20.          $item_cats = get_the_terms($post->ID, 'category_name');
  21.           if($item_cats):
  22.           foreach($item_cats as $item_cat) {
  23.            $item_classes = $item_cat->name ;
  24.           }
  25.           endif;
  26.          
  27.         $list .= '
  28.         <div class="single_wishlist">
  29.             <p>Category Name: '.$item_classes.'</p>
  30.             <div class="wishlist_top">
  31.                 <p>'.get_the_title().'<a href="'.get_the_permalink().'">'.$wishlist_email.'</a></p>
  32.             </div>
  33.             <img src="'.$featured_image_url[0].'" alt="" />
  34.             <img src="'.$theme_dir.'/img/link_style.png" alt="" />
  35.             <div class="wishlist_bottom">
  36.                 ' .get_the_excerpt(). '
  37.             </div>
  38.         </div>
  39.         ';        
  40.     endwhile;
  41.     $list.= '</div>';
  42.     wp_reset_query();
  43.     return $list;
  44. }
  45. add_shortcode('wishlist', 'wishlist_shortcode');   
  46.  
  47. // another way for custom post
  48.  
  49. function page_item_shortcode($atts){
  50. ob_start();
  51.  
  52.     extract( shortcode_atts( array(
  53.         'cat' => '',
  54.         'count' => -1,
  55.     ), $atts, 'page_item' ) );
  56.     $q = new WP_Query(
  57.         array('posts_per_page' => $count, 'post_type' => 'post',  'category_name' => $cat, )
  58.         );    
  59.        
  60.     ?>
  61.     <?php while( $q->have_posts()) : $q->the_post(); ?>
  62.      <div class="homepage_box_one">
  63.                 <div class="main_feature_image box_inner" style="background-image: url(<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), '' ); echo $image[0]; ?>); -ms-background-position-x: center; -ms-background-position-y: center; background-position: center bottom; background-size: cover;">
  64.                     <div class="box_overlay"></div>
  65.                     <div class="box_date"><?php the_time('Y.m.d') ?><br />/<br />by <?php the_author(); ?></div>
  66.                     <i class="fm_icon box_icon">5</i>
  67.                     <div class="box_text text-center">
  68.                         <h1><?php the_title(); ?></h1>
  69.                     </div>
  70.                     <div class="box_excerpt"><?php $post_content = get_the_content(); echo wp_trim_words($post_content, 30 );?></div>
  71.                 </div>
  72.                 <a class="box_button_link" href="<?php the_permalink(); ?>"><?php $categories = get_the_category();
  73.  
  74. if ( ! empty( $categories ) ) {
  75.     echo esc_html( $categories[0]->name );  
  76. }?></a>
  77.             </div>
  78. <?php endwhile; ?>
  79.    
  80.     <?php wp_reset_postdata();
  81.     return ob_get_clean();
  82. }
  83. add_shortcode('page_item', 'page_item_shortcode');
  84.  
  85. /* shorcode for attraction widget */
  86. function attraction_item_shortcode($atts){
  87.     ob_start();    
  88.     extract( shortcode_atts(
  89.     array(        
  90.     'id' => '',  
  91.     ), $atts, 'attraction' ) );    
  92.     $myarray = explode(',', $id);      
  93.     $q = new WP_Query(      
  94.     array('posts_per_page' => -1, 'post_type' => 'attractions-items', 'post__in'=> $myarray
  95.     ));
  96.    
  97.     while( $q->have_posts()) : $q->the_post(); ?>                                  
  98.    
  99.    
  100.         <div class="field-images">
  101.             <a href="<?php the_permalink();?>">
  102.             <img class="high" src="<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'widget-image' ); echo $image[0]; ?>" alt=""/>
  103.             <h5><?php the_title();?></h5>
  104.             </a>
  105.         </div> 
  106.    
  107.    
  108.     <?php endwhile; ?>
  109.    
  110.      
  111.     <?php wp_reset_postdata();    return ob_get_clean();   
  112.    
  113. }
  114. add_shortcode('attraction', 'attraction_item_shortcode');
  115.  
  116. // do shorcode example start
  117. function product_shortcode( $atts, $content = null  ) {
  118.  
  119.     return '
  120.     <div class="post_page_slider_social_area fix">
  121.         <div class="post_page_slider_social column fix">
  122.             <div class="post_page_slider_social_wrapper fix">
  123.                 <div class="post_content_slider section fix">
  124.                     <div class="sc_single_content_slider owl-carousel fix" id="sc_single_content_slider">
  125.                         '.do_shortcode($content).'
  126.                     </div>
  127.                 </div>
  128.             </div>
  129.         </div>
  130.     </div>
  131.     ';
  132. }  
  133. add_shortcode('product', 'product_shortcode');
  134.  
  135.  
  136. function product_item_shortcode( $atts, $content = null  ) {
  137.     extract( shortcode_atts( array(
  138.         'src' => '',
  139.         'title' => '',
  140.     ), $atts ) );
  141.     return '
  142.     <div class="item scscs_single">
  143.         <img src="'.$src.'" alt="'.$title.'" />
  144.     </div>
  145.     ';
  146. }  
  147. add_shortcode('item', 'product_item_shortcode');
  148. // do shorcode example end
  149.  
  150.  
  151. function core_list_shortcode( $atts, $content = null  ) {
  152.  
  153.     extract( shortcode_atts( array(
  154.         'id' => '',
  155.     ), $atts ) );
  156.  
  157.     return 'jQuery("#codeapp'.$id.'").show();';
  158. }  
  159. add_shortcode('core', 'core_list_shortcode');
  160.  
  161.  
  162. function column_shortcode( $atts, $content = null  ) {
  163.     return '<div class="column_content">'.do_shortcode($content).'</div>';
  164. }  
  165. add_shortcode('col', 'column_shortcode');
  166.  
  167.  
  168. ?>
Advertisement
Add Comment
Please, Sign In to add comment