Digitalraindrops

Three Column Category Sample

Oct 27th, 2010
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.99 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Template Name: One Category 3 Column
  4.  *
  5.  * A custom page template Page Name = Category Name .
  6.  *
  7.  * The "Template Name:" bit above allows this to be selectable
  8.  * from a dropdown menu on the edit page screen.
  9.  *
  10.  * @package WordPress
  11.  * @subpackage Twenty_Ten
  12.  * @since Twenty Ten 1.0
  13.  */
  14. get_header(); ?>
  15.    
  16.         <div id="container">
  17.             <div id="content" role="main">
  18. <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
  19.                 <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  20.                     <div class="entry-content">
  21.                         <?php the_content(); ?>
  22.                     </div><!-- .entry-content -->
  23.                 </div><!-- #post-## -->
  24. <?php endwhile; ?>
  25.  
  26.             <?php
  27.             /*
  28.             Run the loop to output the posts.
  29.             Store the page to use later
  30.             */
  31.             global $post;
  32.             $tmp_post = $post;
  33.             //Create a query for the category
  34.             $pageslug = $post->post_name;
  35.             $catslug = get_category_by_slug($pageslug);
  36.             $catid = $catslug->term_id;
  37.             //Get the total Count of posts
  38.             $postotal=(int) get_category($catid)->category_count;
  39.             $query= 'cat=' . $catid. ''; query_posts($query);
  40.             //Round up to the Nearest Whole Number
  41.             $postcount = ceil($postotal/3);    
  42.             ?>
  43.            
  44.             <?php if ( have_posts() ) : ?>
  45.                 <div class="cms-columns"><!-- Add Column Container -->
  46.                     <div class="cms-column"> <!-- Add Column -->
  47.                     <?php /* Start the Loop */ ?>
  48.                     <?php while ( have_posts() ) : the_post(); ?>
  49.                     <?php $counter+=1; ?>
  50.                     <?php if( ($counter !=  $postotal) && !($counter % $postcount) ) : // Remainder = 0 ?>
  51.                         </div> <!-- Close Open Column -->
  52.                         <div class="cms-column"> <!-- Add Column -->
  53.                     <?php endif; ?>
  54.                         <!-- START DO YOUR POST STUFF HERE -->
  55.  
  56.                         <!-- END DO YOUR POST STUFF HERE -->
  57.                     <?php endwhile; ?>
  58.                     </div><!-- Close Open Column -->
  59.                 </div><!-- Close Column Container -->
  60.             <?php endif; ?>
  61.            
  62.             <?php
  63.             //Reset our page to get the sidebar
  64.             $post = $tmp_post;
  65.             ?>
  66.             </div><!-- #content -->
  67.         </div><!-- #container -->
  68.    
  69. <?php get_sidebar(); ?>
  70. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment