Advertisement
alchymyth

multiple loops

Mar 27th, 2011
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.55 KB | None | 0 0
  1. ADAPTED from my post: http://www.transformationpowertools.com/wordpress/playing-with-columns-stacking-posts-grid-style
  2. TWO FULL WIDTH POSTS, AD BLOCK, TWO COLUMNS OF POSTS
  3.  
  4.  
  5. <?php $do_not_duplicate = array();
  6. global $query_string;
  7.  
  8. query_posts( $query_string . '&posts_per_page=2' );
  9. while (have_posts()) : the_post(); ?>
  10.  
  11. <?php //FULL WIDTH POSTS ?>
  12.  
  13. <div class="news_item_a" id="post-<?php the_ID(); ?>">
  14.             <h2 class="contentheading"> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> </h2>
  15.             <div class="newsitem_tools">
  16.               <div class="newsitem_info">
  17.                 <span class="createdate"> <?php the_time('j F Y, h:m') ?> </span> <span class="createby"> <?php the_author() ?> </span>
  18.               </div>
  19.               <!-- end of info-->
  20.             </div>
  21.             <!-- end of tools-->
  22.             <div class="newsitem_text">
  23.               <div class="news_item_article">
  24.               <img class="thumb" src="<?php echo catch_that_image() ?>" border="0" alt="<?php the_title(); ?>" />
  25.                 <?php the_excerpt(); ?>
  26.                 <?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); // for multi page posts ?>
  27.                 <p><a rel="nofollow" class="readon" href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><span style="display: none;"><?php the_title(); ?></span></a></p>
  28.  
  29.               </div>
  30.             </div>
  31.             <span class="article_separator">&nbsp;</span>
  32.          </div>
  33.  
  34. <?php // END OF FULL WIDTH POST ?>
  35.  
  36. <?php $do_not_duplicate[] = $post->ID;
  37.  
  38. endwhile; ?>
  39.  
  40.  
  41. <!--ADVERTISING BLOCK HERE-->
  42. <h2>ADVERTISING</h2>
  43.  
  44.  
  45. <?php //TWO COLUMN POSTS START// ?>
  46.  
  47. <?php
  48. global $query_string;
  49. parse_str( $query_string, $args );
  50. $args['post__not_in'] = $do_not_duplicate;
  51. $args['posts_per_page'] = -1;
  52.  
  53. query_posts( $args );
  54. ?>
  55.  
  56.  
  57. <?php $num_cols = 2; // set the number of columns here
  58.  
  59. for ( $i=1 ; $i <= $num_cols; $i++ ) : ?>
  60.  
  61. <div id="post-column-<?php echo $i; ?>" class="post-column">
  62.  
  63. <?php $counter = $num_cols + 1 - $i;
  64.  
  65. while (have_posts()) : the_post();
  66. if( $counter%$num_cols == 0 ) : ?>
  67.  
  68. <div class="news_item_a column<?php echo $i; ?>" id="post-<?php the_ID(); ?>">
  69.             <h2 class="contentheading"> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> </h2>
  70.             <div class="newsitem_tools">
  71.               <div class="newsitem_info">
  72.                 <span class="createdate"> <?php the_time('j F Y, h:m') ?> </span> <span class="createby"> <?php the_author() ?> </span>
  73.               </div>
  74.               <!-- end of info-->
  75.             </div>
  76.             <!-- end of tools-->
  77.             <div class="newsitem_text">
  78.               <div class="news_item_article">
  79.               <img class="thumb" src="<?php echo catch_that_image() ?>" border="0" alt="<?php the_title(); ?>" />
  80.                 <?php the_excerpt(); ?>
  81.                 <?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); // for multi page posts ?>
  82.                 <p><a rel="nofollow" class="readon" href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><span style="display: none;"><?php the_title(); ?></span></a></p>
  83.  
  84.               </div>
  85.             </div>
  86.             <span class="article_separator">&nbsp;</span>
  87.          </div>
  88.  
  89. <?php endif; $counter++;
  90. endwhile;
  91. rewind_posts(); ?>
  92.  
  93. </div> <!--closes the .post-column div-->
  94.  
  95. <?php endfor; ?>
  96.  
  97.  
  98.  
  99. CSS for the above
  100.  
  101. .post-column { float: left; width: 49%; margin-left: 1%; }
  102. #post-column-1 { margin-left: 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement