Use shortcode for blog category using archive template wordpress

Posted: March 6, 2015 in web
function __construct() {
        add_shortcode('blogs', array($this, 'sc_blogs'));
        $this->model = new Model();
    }

 function sc_blogs($atts){
        $a = shortcode_atts(array(
            'type' => '',
                ), $atts);
         $custom_query = new WP_Query(array('category_name' => $a['type'])); // exclude category 9
            while ($custom_query->have_posts()) : $custom_query->the_post(); ?>
                <?php
                get_template_part('content', get_post_format());
                ?>

            <?php endwhile; ?>         
   
        <?php wp_reset_postdata(); // reset the query 
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s