Skip to content

Instantly share code, notes, and snippets.

@priyabratary
Created July 21, 2016 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save priyabratary/4118651f78abfe7999c4c49a95d4ee14 to your computer and use it in GitHub Desktop.
Save priyabratary/4118651f78abfe7999c4c49a95d4ee14 to your computer and use it in GitHub Desktop.
recent post shortcode
// recent post shortcode
function my_recent_posts_shortcode($atts){
$q = new WP_Query(
array( 'orderby' => 'date', 'posts_per_page' => '-1')
);
$list = '<div class="latest-news p-t-70 p-b-50">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<h1 class="text-center m-b-20">Our <strong>Latest</strong> News</h1>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div id="news" class="owl-carousel owl-theme">';
while($q->have_posts()) : $q->the_post();
$list .= '
<div class="item">
<div class="image-port">
'.get_the_post_thumbnail( get_the_ID(), 'slider', array( 'class' => 'img-responsive' ) ).'
<div class="date">
' . get_the_date() . '
</div>
<div class="post-by">'.get_the_author().'</div>
</div>
<h4 class="m-t-20 m-b-20">' . get_the_title() . '</h4>
<p>' . get_the_excerpt() . '</p>
<a href="' . get_the_permalink() . '" class="btn btn-default pull-right m-t-20">Read More <img src="'.get_template_directory_uri().'/images/more-arrow-org.png" alt=""/></a>
</div>
';
endwhile;
wp_reset_query();
return $list . ' </div>
</div>
</div>
</div>
<div class="customNavigation">
<a class="prev"><img src="'.get_template_directory_uri().'/images/news-prev.png" alt=""/></a>
<a class="next"><img src="'.get_template_directory_uri().'/images/news-next.png" alt=""/></a>
</div>
</div>';
}
add_shortcode('recent-posts', 'my_recent_posts_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment