Advertisement
Guest User

Wordpress Echo Post if In Category

a guest
Jan 16th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. function delicious_promocoes($atts, $content = null) {
  2.     extract(shortcode_atts(array(
  3.         "items" => '2',
  4.     ), $atts));
  5.    
  6.     global $post;
  7.    
  8.     /* DEBUG STARTS HERE - I want to show only posts on the category "destaque" */
  9.     $categories = get_the_category($post->ID);
  10.     var_dump($categories);
  11.     /* DEBUG ENDS HERE - But the var_dump returns array(0) { }*/
  12.    
  13.     $retour ='';
  14.     $retour .= '<div class="centered-wrapper">';
  15.     $retour .= '<section>';
  16.     $retour .= '<ul id="promocoes-home-principal" style="height:300px">';
  17.    
  18.         $args = array(
  19.             'orderby'=> 'post_date',
  20.             'order' => 'rand',
  21.             'post_type' => 'portfolio',
  22.             'posts_per_page' => $items
  23.         );
  24.        
  25.         $my_query = new WP_Query($args);
  26.         if( $my_query->have_posts() ) {
  27.             while ($my_query->have_posts()) : $my_query->the_post();
  28.            
  29.             $portf_icon = get_post_meta($post->ID,'dt_portf_icon',true);   
  30.             $thumb_id = get_post_thumbnail_id($post->ID);
  31.  
  32.             $mythumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'portfolio-thumb');
  33.            
  34.             if ( has_post_thumbnail() ) {
  35.                     $retour .='<li>';
  36.                     $retour .='<a href="'. get_permalink() .'" title="'. get_the_title() .'">';
  37.                     $retour .='<span class="item-on-hover"><span class="hover-link"></span></span>';
  38.                     $retour .='<img src="'. $mythumbnail[0] .'" height="'. $mythumbnail[2] .'" width="'. $mythumbnail[1] .'" alt="'. get_the_title() .'" /></a>';
  39.                     $retour .='<span class="caption"><a href="'. get_permalink() .'">'. get_the_title() .'</a></span>';
  40.                     $retour .='</li>';
  41.             }
  42.             endwhile; wp_reset_query(); }
  43.         $retour .='</ul>';
  44.     $retour .='</section>';
  45.     $retour .='</div><!--end centered-wrapper-->';
  46.    
  47.         return $retour;
  48.  
  49. }
  50.  
  51. add_shortcode("promocoes", "delicious_promocoes");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement