php - Wordpress Shortcode to call latest posts -


i created custom page template display latest 12 posts respective title , excerpt, tought easier if call shortcode.

this loop in "post-grid.php" calls 3 things.

<section class="post-grid">     <?php         $grid = array('post_per_page' => 12);         $query = new wp_query( $grid );         while ( $query->have_posts() ) : $query->the_post();     ?> <div class="grid-posts">     <h2><?php the_title(); ?></h2><br>     <?php the_post_thumbnail('featured'); ?><br>     <?php the_excerpt() ?><br> </div> <?php endwhile; // end of loop. ?> </section> 

how can create shortcode executes loop?

i know how add shortcode using

add_shortcode('postgrid', 'postgrid'); function postgrid() {  //code here } 

but im not sure how implement above function. appreciate help!

  <?php    $args = array(    'post_type' => 'post',    'posts_per_page' => 12,    'paged' => $page,    );   query_posts($args);?>  hope :)   point related add post thumbnail:   // check if post has post thumbnail assigned it.   <?php if (has_post_thumbnail() ) {  the_post_thumbnail();  } the_content(); ?>  

hope :)


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -