Thursday, April 27, 2017

how to show wordpress blog in custom page

//include('blog/wp-load.php');
include($_SERVER['DOCUMENT_ROOT'].'/blog/wp-load.php');

$recent_posts = wp_get_recent_posts(array(
'numberposts' => 4
));

$blogHtml='';
foreach($recent_posts as $post) {
$jsonData[]=$post;
/* echo "<pre>";
print_r($post);
die; */
$imgUrl='';
if (has_post_thumbnail($post['ID'] ) ){
 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post['ID']), 'single-post-thumbnail' );
$imgUrl= $image[0];

}

$post_date  = date('M d, Y',strtotime($post['post_date']));
$post_excerpt = $post['post_excerpt'];
$url  = get_permalink($post['ID']);
$title  = $post['post_title'];

$blogHtml.='<div class="col-md-3">
<div class="post-inner">
 <div class="hds" style="height:190"> <img class="tabl" src="'.$imgUrl.'" alt="blog" height="190"></div>
 <div class="post-container"> <span class="masonry-post-meta">
<time datetime="2015-02-17"> '.$post_date.'</time>
</span>
<h3> '.ucfirst($title).'</h3>
<div class="post-content">
 <p>'.substr($post_excerpt, 0, 400).' […]</p>
 <div class="read-more">
 <a class="btn btn-primary btn-md pull-right" href="'.$url.'">Read More</a></div>
</div>
 </div>
</div>
 </div>';



}
echo $blogHtml;

No comments:

Post a Comment