I have this code to show all post of category and thumbnail for 1st post of them.
<?php $recent = new WP_Query(); ?>
<?php $recent->query( 'cat=1&showposts=5' ); ?>
<?php $is_first_post = true; ?>
<?php while( $recent->have_posts() ) : $recent->the_post(); ?>
<ul>
<li>
<?php
if ( $is_first_post && has_post_thumbnail() ) {
the_post_thumbnail();
$is_first_post = false;
}
?>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
</ul>
<?php endwhile; ?>
but i want show this using shortcode.which using category & post number but i can not make shortcode
First of all you just change your function name.
In wordpress get_posts() is one function so you did not create your custom function same name.
https://developer.wordpress.org/reference/functions/get_posts/
Add this code in function.php and this is your shortcode "[my_form_shortcode cat="1" showposts="5"]".
A shortcode is a PHP function. You need a function that accepts all your arguments. For example-
Your Shortcode will look like this-
This code have not been tested but this is pretty much how you do it
http://www.codexwp.com/issues/how-to-create-shortcode-in-wordpress/