Create Shortcode and get Shortcode

/*
Home Pahe Slider Shortcode
*/
function HomeSlider($args){
$posttype = $args[‘post_type’];
$limit = $args[‘limit’];
$order = $args[‘order’];
$args = array( ‘post_type’ => $posttype, ‘posts_per_page’ => $limit, ‘order’ => $order );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$sliderimageUrl = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div class=”item”><img src=”<?php echo $sliderimageUrl;?>” alt=”<?php the_title();?>” />
<div class=”banner-content”>
<h3><?php the_title();?></h3>
<?php the_content();?>
<a href=”<?php the_permalink();?>”>Visit Showroom</a>
</div>
</div>
<?php endwhile;

}
add_shortcode(“Slider”,”HomeSlider”);

/*******************  Get Shortcode*********************/

<?php echo do_shortcode(“[Slider post_type=slider limit=4 order=DESC]”); ?>

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