Last active
October 28, 2015 16:55
-
-
Save tedgeving/a32b495bdf588ab9cdd1 to your computer and use it in GitHub Desktop.
Display a list of Wordpress pages with Bootstrap rows and columns markup. This example has 3 items to a row. (3 by N number of rows)
This file contains 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 | |
/** | |
* Display a list of Worpress pages with Bootstrap rows and columns markup. This example has 3 items to a row. (3 by N number of rows) | |
*/ | |
$pages = get_posts(array( 'orderby' => 'menu_order', 'post_type' => 'pages', 'numberposts' => -1, 'order'=> 'ASC' )); | |
$totalpages = count($pages); | |
$count =0; | |
foreach ($pages as $k => $v) { | |
// create bootstrap row for first item | |
if($count % 3 == 0){ | |
echo'<div class="row">'; | |
} | |
?> | |
<div class="col-md-4"> | |
<!-- modify grid contents to suit --> | |
<a href="<?= get_page_link( $v->ID )?>" rel="bookmark" title="Permanent Link to <?= $v->post_title ?>"> | |
<?= get_the_post_thumbnail($v->ID, 'full-size', array('class'=>'img-responsive')); ?> | |
<h3><?php echo $v->post_title; ?></h3> | |
</a> | |
</div> | |
<?php | |
// close row on every 3rd item | |
if($count % 3 == 2){ | |
echo'</div>'; | |
} | |
++$count; | |
// close row on last item | |
if($count == $totalpages){ | |
echo'</div">'; | |
} | |
} // end foreach | |
?> | |
<!-- | |
The above will produce the following output | |
<div class="row"> | |
<div class="col md-4"> | |
... | |
</div> | |
<div class="col md-4"> | |
... | |
</div> | |
<div class="col md-4"> | |
... | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col md-4"> | |
... | |
</div> | |
... | |
</div> | |
--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment