Skip to content

Instantly share code, notes, and snippets.

@awakekat
Created March 28, 2016 17:26
Show Gist options
  • Save awakekat/129c63c732099d067f1a to your computer and use it in GitHub Desktop.
Save awakekat/129c63c732099d067f1a to your computer and use it in GitHub Desktop.
WP Posts by Category
<?php
/*
Template Name: Post by Category
*/
get_header(); ?>
<div id="container">
<div id="content" role="main">
// store categories in varialble $cats
<?php $cats = get_categories();
// loop
foreach ($cats as $cat) {
$cat_id = $cat->term_id;
echo "<h2>".cat->name."- $cat_id</h2>"
//custom loop
query_posts("cat=$cat_id$posts_per_page=50");
if (have_posts()) : while(have_posts()) : the_post(); ?>
<a href="<?php the_permalink();?>"><?php the_title(); ?></a>
<?php echo <br> ; ?>
<?php endwhile; endif; ?>
<?php }
?>
</div><!-- #content -->
</div><!-- #container -->
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment