madeinthearcade
2/22/2017 - 11:07 PM

Show every X number of posts in a row, show all recents posts in all categories and standard show all on index

Show every X number of posts in a row, show all recents posts in all categories and standard show all on index

<?php 
$args = array(
	'numberposts' => 5,
	'cat' => 27
);
$posts = get_posts($args);
if ( $posts ) : ?>
<div class="fullwidth-section">
	<div class="latest-posts">
		<h2 class="text-center">Latest News</h2>
		<div class="latest-posts-slider owl-carousel">
		<?php foreach ( $posts as $post ) : setup_postdata( $post ); ?>
			<article>
			<?php if ( has_post_thumbnail() ) : ?>
				<a href="<?php the_permalink(); ?>" class="ft-post-img">
					<?php the_post_thumbnail('full', array( 'class' => 'img-full' )); ?>
				</a>
			<?php endif; ?>
				<h5>
					<a href="<?php the_permalink(); ?>">
						<?php the_title(); ?>
					</a>
					<span class="date"><?php the_time('j F, Y'); ?></span>
				</h5>
				<p>
				<?php if ( has_excerpt( $post->ID ) ) {
					echo limit_words(get_the_excerpt(), '10') . '...';
					} 
					else {
					echo limit_words(get_the_content(), '10') . '...';
					}
				?>
				</p>
				<a href="<?php the_permalink(); ?>" class="btn">
					Read article
				</a>
			</article>
		<?php endforeach; wp_reset_postdata(); ?>
		</div>
	</div>
</div>
<?php endif; ?>
<?php if ( have_posts() ) : ?>
	<ul class="recent-post">
		<?php while ( have_posts () ) : the_post(); ?>
			<li>
				<h5 class="no-dash">
					<a href="<?php the_permalink(); ?>">
						<span><?php the_time('j F, Y'); ?></span>
						<?php the_title(); ?>
						<br>
						<small>
						<?php if ( has_excerpt( $post->ID ) ) {
							echo limit_words(get_the_excerpt(), '40') . '...';
							} 
							else {
							echo limit_words(get_the_excerpt(), '40') . '...';
							}
						?>
						</small>
					</a>
				</h5>
			</li>
		<?php endwhile; ?>
	</ul>
<?php endif; ?>
<?php $i = 0; ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php if( $i == 0 ) {
	echo '<div class="row">';
	}
?>
	
	<div class="col-md-6 col-lg-4">
		<article <?php post_class( 'news-article-listing' ); ?> role="article">
			<a href="<?php the_permalink(); ?>" class="featured-image">
				<?php if ( has_post_thumbnail() ) {
					the_post_thumbnail('medium');
					}
				?>
			</a>
			<div class="post-excerpt">
				<h5 class="no-dash">
					<span><?php the_time('j F, Y'); ?> - <?php the_category( ' ' ); ?></span>
					<a href="<?php the_permalink(); ?>">
						<?php the_title(); ?>
					</a>
				</h5>
				<p>
					<?php if(has_excerpt( $post->ID )) {
						echo the_excerpt();
					} else {
						echo limit_words(get_the_excerpt(), '25') . '...';
					} ?>
					<a href="<?php the_permalink(); ?>" class="gradient-btn">
						<span>View <?php the_title(); ?></span>
					</a>
				</p>
			</div>
		</article>
	</div>

	<?php 
		$i++;
		if ( $i == 3 ) {
			$i = 0;
			echo '</div>';
			}
		?>

		<?php endwhile; ?>

		<?php
			if ( $i > 0 ) {
				echo '</div>';
				}
			?>

		<?php else : ?>

		<article id="post-not-found" class="hentry cf">
			<header class="article-header">
				<h1><?php _e( 'Oops, Post Not Found!', 'bonestheme' ); ?></h1>
			</header>
			<section class="entry-content">
				<p><?php _e( 'Uh Oh. Something is missing. Try double checking things.', 'bonestheme' ); ?></p>
			</section>
			<footer class="article-footer">
				<p><?php _e( 'This is the error message in the archive.php template.', 'bonestheme' ); ?></p>
			</footer>
		</article>

<?php endif; ?>
<?php html5wp_pagination(); ?>
//Show all recent posts in all categories if post page is set to index and you want to display them on page-home

<?php $the_query = new WP_Query( 'posts_per_page=5' ); if ( $the_query->have_posts() ) : ?>
	<ul class="recent-post">
		<?php while ( $the_query->have_posts () ) : $the_query->the_post(); ?>
			<li>
				<h5 class="no-dash">
					<a href="<?php the_permalink(); ?>">
						<span><?php the_time('j F, Y'); ?></span>
						<?php the_title(); ?>
						<br>
						<small>
						<?php if ( has_excerpt( $post->ID ) ) {
							echo limit_words(get_the_excerpt(), '40') . '...';
							} 
							else {
							echo limit_words(get_the_excerpt(), '40') . '...';
							}
						?>
						</small>
					</a>
				</h5>
			</li>
		<?php endwhile; ?>
	</ul>
<?php endif; ?>