Last active
August 29, 2015 14:00
-
-
Save emaildano/11182387 to your computer and use it in GitHub Desktop.
Group blog posts by category boilerplate.
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 | |
// get all the categories from the database | |
$cats = get_categories(); | |
// loop through the categries | |
foreach ($cats as $cat) { | |
// setup the cateogory ID | |
$cat_id= $cat->term_id; ?> | |
<h2><?php echo $cat->name ?></h2> | |
<?php | |
$args = array( | |
'cat' => $cat_id, | |
'posts_per_page' => 3 | |
); | |
query_posts($args); | |
// start the wordpress loop! | |
if (have_posts()) : while (have_posts()) : the_post(); ?> | |
<?php get_template_part('templates/post-module'); ?> | |
<?php endwhile; endif; // done our wordpress loop. Will start again for each category ?> | |
<?php } // done the foreach statement ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment