Advertisement
olie480

WP - List all Categories and Posts

Oct 29th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. <?php
  2. /* template name: Posts by Category! */
  3. get_header(); ?>
  4.  
  5.         <div id="container">
  6.             <div id="content" role="main">
  7.  
  8.             <?php
  9.             // get all the categories from the database
  10.             $cats = get_categories();
  11.  
  12.                 // loop through the categries
  13.                 foreach ($cats as $cat) {
  14.                     // setup the cateogory ID
  15.                     $cat_id= $cat->term_id;
  16.                     // Make a header for the cateogry
  17.                     echo "<h2>".$cat->name."</h2>";
  18.                     // create a custom wordpress query
  19.                     query_posts("cat=$cat_id&post_per_page=100");
  20.                     // start the wordpress loop!
  21.                     if (have_posts()) : while (have_posts()) : the_post(); ?>
  22.  
  23.                         <?php // create our link now that the post is setup ?>
  24.                         <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
  25.                         <?php echo '<hr/>'; ?>
  26.  
  27.                     <?php endwhile; endif; // done our wordpress loop. Will start again for each category ?>
  28.                 <?php } // done the foreach statement ?>
  29.  
  30.             </div><!-- #content -->
  31.        </div><!-- #container -->
  32.  
  33. <?php get_sidebar(); ?>
  34. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement