kalponikoronno

custom post query into shortcode

Jan 3rd, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. function services_shortcode($atts, $content = null) {
  5.     extract(shortcode_atts(array(
  6.    
  7.     ), $atts));
  8.         $q = new WP_Query(
  9.              array('posts_per_page' => '4', 'post_type' => 'services')
  10.         );
  11.             $list .= '';
  12.                 while($q->have_posts()) : $q->the_post();
  13.                     $idd = get_the_ID();
  14.                     $emedic = get_post_meta($idd, 'emedic', true);
  15.                    
  16.                     $list .= '';           
  17.  
  18.                 endwhile;
  19.             $list .= '';   
  20.         wp_reset_query();                  
  21.     return $list;
  22. }
  23. add_shortcode('servicepost', 'services_shortcode');
  24.  
  25.  
  26. function mix_content_shortcode($atts, $content = null) {
  27.         extract(shortcode_atts(array(
  28.             'count' => '',
  29.             'category' => '',
  30.         ), $atts));
  31.             $q = new WP_Query(
  32.                  array('posts_per_page' => $count, 'post_type' => 'mixitup_item', 'mixit_cat' => $category)
  33.             );
  34.                     $list .= '<div id="worksGrid">';
  35.                         while($q->have_posts()) : $q->the_post();
  36.                             $idd = get_the_ID();
  37.                             $image_id = get_post_thumbnail_id();
  38.                             $image_url = wp_get_attachment_image_src($image_id,'thumbimage');  
  39.                             $image_thmb = $image_url[0];
  40.                             $mixcategory = get_post_meta($idd, 'mixcategory', true);
  41.                             $mixsubtitle = get_post_meta($idd, 'mixsubtitle', true);
  42.                             $mixlargeimage = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'mlimage');
  43.                             $list .= '
  44.                            
  45. <div class="col-md-4 col-sm-4 col-xs-12 worksItem '.$mixcategory.'">
  46.     <img src="'.$image_thmb.'" alt="">
  47.     <div class="itemCaption">
  48.         <div class="capContent">
  49.             <h3>'.get_the_title().'</h3>
  50.             <p>'.$mixsubtitle.'</p>
  51.             <a class="capPreview image-modal" href="#image-modal'.get_the_ID().'">Preview</a>
  52.         </div>
  53.     </div>  
  54.     <div id="image-modal'.get_the_ID().'" class="mfp-hide modal-box">
  55.         <img src="'.$mixlargeimage[0].'" alt="">
  56.           <div class="modal-box-content">
  57.             <h2>'.get_the_title().'</h2>
  58.             <p>'.get_the_content().'</p>
  59.           </div>
  60.     </div>
  61. </div>                         
  62.                            
  63.                             ';         
  64.        
  65.                         endwhile;
  66.                     $list .= '</div>'; 
  67.             wp_reset_query();                  
  68.         return $list;
  69. }
  70. add_shortcode('portfolioitem', 'mix_content_shortcode');
  71.                    
  72.  
  73.  
  74.  
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment