Created
December 22, 2015 16:17
-
-
Save maxkostinevich/66552291b2007f3937c6 to your computer and use it in GitHub Desktop.
WordPress Custom Loop Markup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Loop Markup (lm) | |
// Show 9 posts | |
// add "first" class for each first post in line (3 per line) | |
$lm_ItemsPerLine=3; | |
$lm_CurrentItem=1; | |
$lm_LineClose=''; | |
$lm_LineOpen='<div style="overflow:hidden;">'; | |
query_posts(array ('posts_per_page' =>9) ); | |
if (have_posts()) : while (have_posts()) : the_post(); ?> | |
<?php $first_post_class='';?> | |
<?php if($lm_CurrentItem==1){echo $lm_LineOpen; $lm_LineClose='</div>';$first_post_class=' first';}?> | |
<article id="post-<?php the_ID(); ?>" <?php post_class( 'clearfix fourcol'.$first_post_class ); ?> > | |
<header class="article-header"> | |
<h3 class="h2"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3> | |
</header> | |
<section class="entry-content clearfix" itemprop="articleBody"> | |
<?php the_excerpt(); ?> | |
</section> | |
</article> | |
<?php if($lm_CurrentItem==$lm_ItemsPerLine){echo $lm_LineClose;$lm_CurrentItem=0;$lm_LineClose='';} $lm_CurrentItem++;?> | |
<?php | |
endwhile;?> | |
<?php echo $lm_LineClose;?> | |
<?php else : ?> | |
<article id="post-not-found" class="hentry clearfix"> | |
<header class="article-header"> | |
<h1><?php _e( 'Oops, Post Not Found!', 'theme' ); ?></h1> | |
</header> | |
<section class="entry-content"> | |
<p><?php _e( 'Uh Oh. Something is missing. Try double checking things.', 'theme' ); ?></p> | |
</section> | |
<footer class="article-footer"> | |
<p><?php _e( 'This is the error message in the page.php template.', 'theme' ); ?></p> | |
</footer> | |
</article> | |
<?php endif; | |
// Reset Query | |
wp_reset_query(); | |
?>` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment