function.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | function home_blogs(){ $args = array( 'posts_per_page' => 3, /* how many post you need to display */ 'offset' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', /* your post type name */ 'post_status' => 'publish' ); $wp_query = new WP_Query($args); if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); $excerpt = get_the_excerpt(); $excerpt = substr($excerpt, 0, 145); $exc_result = substr($excerpt, 0, strrpos($excerpt, ' ')); $post_thumb = get_the_post_thumbnail_url( get_the_ID(), 'medium' ); if($post_thumb) { $post_thumb2 = $post_thumb; }else{ $post_thumb2 = get_template_directory_uri().'/assets/images/default-post.jpg'; } ?> <!-- Box starts --> <div class="col-lg-4 col-md-4 col-sm-12 blog-box"> <div class="blog-box-inn"> <div class="blog-box-img"> <img src="<?php echo $post_thumb2; ?>" alt=""> </div> <div class="blog-box-content"> <h3 class="box-heading"><?php the_title(); ?></h3> <ul class="blog-box-info"> <li><?php $post_date = get_the_date( 'l F j, Y' ); echo $post_date; ?></li> <li>|</li> <li>Admin</li> </ul> <p> <?php echo $exc_result; ?> </p> <a href="<?php the_permalink(); ?>" class="btn-comm-brdr">Read more <i class="fas fa-angle-right"></i></a> </div> </div> </div> <!-- Box ends --> <?php endwhile; endif; } add_shortcode('home_blogs_short', 'home_blogs'); |
anytheme
1 2 3 | <div> <?php echo do_shortcode('[home_blogs_short]'); ?> </div> |