Created
March 28, 2016 17:26
-
-
Save awakekat/129c63c732099d067f1a to your computer and use it in GitHub Desktop.
WP Posts by Category
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 | |
/* | |
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