<?php
function blogpost($atts)
{
    extract(shortcode_atts(array(
        'member'       => '4',
        'type'       => ''
    ), $atts));
    
    $team_return = '';
	if($type == 'style1')
    {
        $args1 = array(
            'post_type'         => array('post'),
            'post_status'       => array('publish'),
            'posts_per_page'    => $member,
            'orderby'           => 'date',
            'order'             => 'DESC'
        );
        
        query_posts($args1);
        if(have_posts())
        {
            
		$team_return .= '<div class="content-blog">';
            while(have_posts())
            {
                the_post();
                $des1 = get_post_meta(get_the_ID(), 'designation', TRUE);
				if($des1 != '')
				{
					$desig = $des1;
				}
				else
				{
					$desig = '';
				}
				
				$ida = get_post_thumbnail_id( get_the_ID() );
				if(has_post_thumbnail( get_the_ID() ))
				{
					$blog_thumb = get_the_post_thumbnail(get_the_ID(), 'blog_thumb');
				}
				else
				{
					$blog_thumb = '<img src="http://placehold.it/360x252/cccccc&amp;text=IMAGE" alt="Blog Image"/>';
				}
				$termsn = wp_get_post_terms( get_the_ID(), 'category');
				$te = '';
				foreach($termsn as $termn)
				{
					$te .= ''.esc_attr($termn->name).'';
				}
				$team_return .='
				<div class="blog-item">
					<div class="blog-title">
						<a title="" href="'.get_the_permalink().'">
							<h2>'.get_the_title().'</h2>
						</a>
					</div>

					<p class="blog-descript">
						'.substr(get_the_content(), 0, 300).' 
					</p>

					<div class="blog-info">
						posted by '.get_the_author().' on '.get_the_time('F').' '.get_the_time('j').', '.get_the_time('Y').' in '.$te.' / '.get_comments_number().' comments
					</div>
				</div>';
            }
		$team_return .= '</div>';
        }
        else
        {
            $team_return .= '<div class="col-lg-12 text-center">';
                $team_return .= '<h1 class="common_main_heading">Please Insert Some <span>Blog Post</span> First.</h1>';
            $team_return .= '</div>';
        }
        wp_reset_query();
    }
    elseif($type == 'style2')
    {
		$args1 = array(
            'post_type'         => array('post'),
            'post_status'       => array('publish'),
            'posts_per_page'    => 2,
            'orderby'           => 'date',
            'order'             => 'DESC'
        );
        
        query_posts($args1);
        if(have_posts())
        {
			$team_return .= '<ul class="events">';
			while(have_posts())
			{
			the_post();
			$team_return .='
						<li>
							<div class="icon">
								<i class="icon-calendar-1"></i>
							</div>
							<h4>'.get_the_time('F').' '.get_the_time('j').', '.get_the_time('Y').'</h4>
							<p>'.substr(get_the_content(), 0, 50).' </p>
						</li>';
			}
			$team_return .= '</ul>';
		}
		else
        {
            $team_return .= '<div class="col-lg-12 text-center">';
                $team_return .= '<h1 class="common_main_heading">Please Insert Some <span>Blog Post</span> First.</h1>';
            $team_return .= '</div>';
        }
        wp_reset_query();
	}
	elseif($type == 'style3')
    {
		$args1 = array(
            'post_type'         => array('post'),
            'post_status'       => array('publish'),
            'posts_per_page'    => $member,
            'orderby'           => 'date',
            'order'             => 'DESC'
        );
        
        query_posts($args1);
        if(have_posts())
        {
			while(have_posts())
			{
			the_post();
			$ida = get_post_thumbnail_id( get_the_ID() );
			if(has_post_thumbnail( get_the_ID() ))
			{
				$blog_thumb = get_the_post_thumbnail(get_the_ID(), 'blog_thumb');
			}
			else
			{
				$blog_thumb = '<img src="http://placehold.it/360x252/cccccc&amp;text=IMAGE" alt="Team Member"/>';
			}
			$team_return .='
			<div class="col-sm-4 blog-single">
				<div class="blog-Image">
					<a href="'.wp_get_attachment_url($ida).'" class="lightbox">
						'.$blog_thumb.'
					</a>
				</div>

				<div class="blog-author">
					<div class="Image">'.get_avatar( '' ).'</div>
					<p>by '.get_the_author().'</p>
				</div>

				<div class="blog-title text-left">
					<h2>'.get_the_title().'</h2>
				</div>

				<!-- .blog-content -->
				<div class="blog-content">
					'.substr(get_the_content(), 0, 100).'
				</div>
				<!-- / .blog-content -->

				<a href="'.get_the_permalink().'" class="comments-cont"><i class="icon-notepad-1"></i>'.get_comments_number().' Comments</a>
			</div>';
			}
		}
		else
        {
            $team_return .= '<div class="col-lg-12 text-center">';
                $team_return .= '<h1 class="common_main_heading">Please Insert Some <span>Blog Post</span> First.</h1>';
            $team_return .= '</div>';
        }
        wp_reset_query();
	}
    return $team_return;
}
add_shortcode( "rms-blogpost", "blogpost" );