Respostas no Fórum

Visualizando 1 resposta (de um total de 1)
  • Criador do tópico digofreitas

    (@digofreitas)

    Consegui!

    Segue o código:

    function recent_posts_with_thumbnails( $atts ) {
    	// Attributes
    	extract( shortcode_atts(
    		array(
    			'post_count' => 10,
    			'post_type' => 'post',
    			'taxonomy_name' => 'category',
    			'taxonomy_slugs' => '',
    			'order' => 'DESC',
    			'width' => 100,
    			'height' => 100,
    		), $atts )
    	);
    
    // Code
    
    $query_atts = array(
    	'post_type' => $atts['post_type'],
    	'posts_per_page' => $atts['post_count'],
    );
    
    $tax_query_array = array();
    
    if (!empty($atts['taxonomy_name'])){
    	$tax_query_array['taxonomy'] = $atts['taxonomy_name'];
    	$tax_query_array['field'] = 'slug';
    
    	if (!empty($atts['taxonomy_slugs'])){
    		$tax_query_array['terms'] = split(',',$atts['taxonomy_slugs']);
    	}
    }
    
    if (!empty($tax_query_array)){
    	$query_atts['tax_query'] = array($tax_query_array);
    }
    
    //return json_encode($query_atts);
    query_posts( $query_atts );
    
    // The Loop
    while ( have_posts() ) :
    	$a_post = the_post();
    	$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($a_post->ID), array($atts['width'],$atts['height']));
    	$img_src = $thumb['0'];
    	$output .= '<a href="'.get_permalink($a_post->ID).'" title="'.$a_post->post_title.'"><img src="'.$img_src.'"/></a>';
    endwhile;
    
    // Reset Query
    wp_reset_query();
    
    return $output;
    }
    
    add_shortcode( 'recent_posts_with_thumbnails', 'recent_posts_with_thumbnails' );
Visualizando 1 resposta (de um total de 1)