Advertisement
alchymyth

multi loop for recent categories

Sep 24th, 2011
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.33 KB | None | 0 0
  1. <?php $allposts = get_posts('post_type=post&numberposts=120'); //get a lot of recent posts
  2. $cats = array(); $cat = array(); //initialize arrays
  3. foreach($allposts as $allpost) {
  4. $postcats = get_the_category($allpost->ID); //get all post's categories
  5. foreach($postcats as $ca) { $cat[] = $ca->term_id; } $postcats = $cat; $cat = array(); //this uses less queries than wp_get_post_categories()
  6. $cats = array_merge($cats,$postcats);
  7. $cats = array_unique($cats); } //only keep unique category IDs
  8. // $cats should now hold the list of cat IDs in chronological order
  9.  
  10. //you need to fill in the following section with the category slugs and css classes and titles that you use in your ten loops
  11.  
  12. /*set the css classes asociated with the categories*/
  13. $cat_class['aciform'] = 'maintitle_acifo';
  14. $cat_class['uncategorized'] = 'maintitle_uncat';
  15. $cat_class['contact'] = 'maintitle_conta';
  16.  
  17. /*set the main titles asociated with the categories*/
  18. $cat_title['aciform'] = 'Aciform Title';
  19. $cat_title['uncategorized'] = 'Uncat Title';
  20. $cat_title['contact'] = 'Conta Title';
  21.  
  22. $i = 0;
  23. foreach( $cats as $cat ) : //start the big loop through the latest categories
  24. $this_cat = get_category($cat); echo $this_cat->slug; ?>
  25.  
  26. <div class="<?php echo $cat_class[$this_cat->slug]; ?>"><?php echo $cat_title[$this_cat->slug]; ?><?php if($i == 0) { ?><a href="" style="float:right;margin-right:10px;font-size:14px;margin-top:4px;">See All Videos</a><?php } ?></div>
  27.                 <div class="padder">
  28.  
  29.                 <div class="page" id="blog-latest">
  30.  
  31.                         <?php  query_posts('category_name='.$this_cat->slug.'&showposts=12&order=DESC'); if ( have_posts() ) : ?>
  32.                                
  33. <?php $i=0; while (have_posts()) : the_post();  $i++; ?>
  34.                                       <?php do_action( 'bp_before_blog_post' ) ?>
  35.  
  36.                                         <div class="postbox_white">
  37.                                         <div class="boxtitle_white">
  38.                                                                         <h2><a href="<?php the_permalink() ?>" style='color:#fff' orel="bookmark" title="<?php the_title_attribute(); ?>"><?php echo tube_get_limited_string($post->post_title,20); ?></a></h2>
  39.                                
  40.                                 </div>
  41.                                 <div class="boxentry_white">
  42.  
  43.                                     <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
  44.                                                                         <?php $thumb = tube_getcustomfield('thumb',get_the_ID()); if(!empty($thumb)) { ?>
  45.                                     <img src="<?php echo $thumb; ?>" alt="<?php the_title_attribute(); ?>" width="130" height="78" /> <?php } else { ?>
  46.                                     <img src="<?php bloginfo('template_url') ?>/images/pic_post1.jpg" width="130" height="78" alt="image" /><?php } ?>
  47.                                     </a>
  48. <div class='post_date'>
  49.                       <?php the_author() ?></div>
  50.                                 </div>
  51.                                
  52.                                 </div>
  53.  
  54.                                         <?php do_action( 'bp_after_blog_post' ) ?>
  55.                             <?php if($i%4==0) : ?><div class="clear"></div><?php endif; ?>
  56.  
  57.                                 <?php endwhile; ?>
  58.  
  59.                                 <div class="navigation">
  60.  
  61.                                         <div class="alignleft"><?php next_posts_link( __( '&larr; Previous Entries', 'buddypress' ) ) ?></div>
  62.                                         <div class="alignright"><?php previous_posts_link( __( 'Next Entries &rarr;', 'buddypress' ) ) ?></div>
  63.  
  64.                                 </div>
  65.  
  66.                         <?php else : ?>
  67.  
  68.                                 <h2 class="center"><?php _e( 'Not Found', 'buddypress' ) ?></h2>
  69.                                 <p class="center"><?php _e( 'Sorry, but you are looking for something that isn\'t here.', 'buddypress' ) ?></p>
  70.  
  71.                                 <?php locate_template( array( 'searchform.php' ), true ) ?>
  72.  
  73.                         <?php endif; ?>
  74.                 </div>
  75.  
  76.                 <?php do_action( 'bp_after_blog_home' ) ?>
  77.  
  78. </div><!-- .padder -->
  79.  
  80. <?php endforeach; //end of the big loop ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement