<?php
/**
* Template Name: Custom Page Template
*/
?>
<?php get_header(); ?>

<div class="container">

	<div class="">
		<h1 style="">Custom Page Template</h1>
	</div>

	<div class="">
		<p></p>
	</div>

	<?php

	$i = 0;

	$args = array (
		'post_type'	=> 'custom-post-type',
	);

	$query = new WP_Query( $args ); 

	if ( $query->have_posts() ) {
		while ( $query->have_posts() ) {
			$query->the_post();

			$post_id = $query->ID;

			$x = get_field( "x" );
			$xx = get_field( "xx" );
			$xxx = wp_trim_words( get_field( "xxx" ), $num_words = 25, $more = '...' );

			if($i % 4 == 0){ ?>

			<div class="row">

			<?php } ?>

			<div class="col-sm-3">
				<h3 style="margin:5px 0 5px;"><?php the_title(); ?></h3>
				<a href="<?php the_permalink(); ?>"><img src="<?php echo $x; ?>" /></a>
				<p style="margin-bottom:10px;"><?php echo $xx; ?></p>
				<p class="read-more-link"><a href="<?php the_permalink(); ?>">Read More</a></p>
			</div>

			<?php

			$i++;

			if($i % 4 == 0){ ?>

			</div>

			<?php }

		} 

	} else {
	echo 'No Posts to Show.';
	}

	wp_reset_postdata();

	?>
	</div>	

</div><!-- .container -->

<?php get_footer();