Display post by Category Slug
Display post by Category Slug
// Add Shortcode function custom_shortcode() { // Add Shortcode function custom_shortcode( $atts , $content = null ) { // Attributes $atts = shortcode_atts( array( 'posts_per_page' => '3', 'category_slug' => '', ), $atts, 'category_posts' ); // Query $the_query = new WP_Query( array ( 'posts_per_page' => '3', 'category_name' => $atts['category_slug'] ) ); // Posts $output = '<ul class="g1-grid">'; while ( $the_query->have_posts() ) : $the_query->the_post(); $output .= '<li class="g1-column g1-one-third"> <div id="white-box" class="news-box"> <p class="news-text"><strong>' . get_the_title() . '</strong> <br /> '. get_the_content() .'</p> </div> </li>'; endwhile; $output .= '</ul>'; // Reset post data wp_reset_postdata(); // Return code return $output; } add_shortcode( 'category_posts', 'custom_shortcode' ); } add_shortcode( '', 'custom_shortcode' );