GO BACK

Contact Us

5-E / 22 BP , 2nd Floor
Near BK Chowk
121001
Faridabad (Haryana), INDIA

Home Forums WordPress Create ShortCode Parameters to add number of recent posts in Page? Reply To: Create ShortCode Parameters to add number of recent posts in Page?

#1849 Reply

admin
Keymaster

Hi Nancy,

Use this code to solve your error.

Add this code into your function.php file.

function recent_posts_function($atts){
   extract(shortcode_atts(array(
      'posts' => 1,
   ), $atts));

   $return_string = '<ul>';
   query_posts(array('orderby' => 'date', 'order' => 'DESC' , 'showposts' => $posts));
   if (have_posts()) :
      while (have_posts()) : the_post();
         $return_string .= '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
      endwhile;
   endif;
   $return_string .= '</ul>';

   wp_reset_query();
   return $return_string;
}
add this short code, where you want to display your recent post list.

 [recent-posts posts="5"]

Regards
Tech9logy Creators

img