Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function category_post_shortcode($atts){
- extract( shortcode_atts( array(
- 'title' => '',
- 'category' => '',
- ), $atts, 'category_post' ) );
- $q = new WP_Query(
- array( 'category' => $category, 'posts_per_page' => '3', 'post_type' => 'post')
- );
- $list = '<div class="short"><h2>'.$title.'</h2>';
- while($q->have_posts()) : $q->the_post();
- //get the ID of your post in the loop
- $id = get_the_ID();
- $post_excerpt = get_post_meta($id, 'post_excerpt', true);
- $post_thumbnail= get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
- $list .= '
- <div class="sin_short">
- <h2>'.get_the_title().'</h2>
- '.$post_thumbnail.'
- <p>'.$post_excerpt.'</p>
- <a href="'.get_permalink().'">more</a>
- </div>
- ';
- endwhile;
- $list.= '</div>';
- wp_reset_query();
- return $list;
- }
- add_shortcode('category_post', 'category_post_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement