Advertisement
alchymyth

loop-grid.php / grab first image

Jun 25th, 2011
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.63 KB | None | 0 0
  1. <?php
  2. /**
  3.  * The loop to show posts in columns
  4.  *
  5.  * loop-grid.php
  6.  
  7.  * @package WordPress
  8.  * @subpackage Twenty Ten
  9.  * @since 3.0.0
  10.  */
  11. ?>
  12.  <?php global $query_string; query_posts( $query_string .'&posts_per_page=40'); //set number of posts ?>
  13. <?php /* Display navigation to next/previous pages when applicable */ ?>
  14. <?php if ( $wp_query->max_num_pages > 1 ) : ?>
  15.         <div id="nav-above" class="navigation">
  16.         <?php if( function_exists('wp_pagenavi') ) :
  17. wp_pagenavi();
  18. else : ?>
  19.                 <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
  20.                 <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
  21.         <?php endif; ?>
  22.         </div><!-- #nav-above -->
  23. <?php endif; ?>
  24.  
  25. <?php /* If there are no posts to display, such as an empty archive page */ ?>
  26. <?php if ( ! have_posts() ) : ?>
  27.         <div id="post-0" class="post error404 not-found">
  28.                 <h1 class="entry-title"><?php _e( 'Not Found', 'twentyten' ); ?></h1>
  29.                 <div class="entry-content">
  30.                         <p><?php _e( 'Apologies, but no results were found for the requested Archive. Perhaps searching will help find a related post.', 'twentyten' ); ?></p>
  31.                         <?php get_search_form(); ?>
  32.                 </div><!-- .entry-content -->
  33.         </div><!-- #post-0 -->
  34. <?php endif; ?>
  35.  
  36. <?php /* Start the Loop */ ?>
  37.  
  38.  
  39. <?php $num_cols = 5; // set the number of columns here
  40.  
  41. for ( $i=1 ; $i <= $num_cols; $i++ ) :
  42. echo '<div id="col-' . $i . '" class="col" >';
  43. $counter = $num_cols + 1 - $i; ?>
  44.  
  45. <?php while (have_posts()) : the_post();
  46. if( $counter%$num_cols == 0 ) :
  47. // begin of core posts output ?>
  48.  
  49.  
  50. <?php $bg_img = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID) ); ?>
  51. <?php $bg_img = esc_attr($bg_img[0]); ?>
  52. <?php if( !$bg_img ) { $bg_img = get_first_image(); } //if ther is no featured image, try to get the first image from the post ?>
  53.              <div id="post-<?php the_ID(); ?>" <?php post_class(); ?> <?php if( $bg_img ) { echo ' style="background-image: url(' . $bg_img . '); "'; } ?>>
  54.                         <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Play %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><span><?php the_title(); ?></span></a></h2>
  55.                        
  56.                        
  57.                        
  58.  
  59.                        
  60.                        
  61.  
  62.                 </div><!-- #post-<?php the_ID(); ?> -->
  63.                 <?php // global $withcomments; $withcomments = 1;
  64.                 //comments_template( '', true ); ?>
  65.  
  66. <?php //end of posts output
  67.  
  68. endif; $counter++;
  69. endwhile;
  70. rewind_posts();
  71. echo '</div>'; //closes the column div
  72. endfor; ?>
  73.  
  74. <?php /* Display navigation to next/previous pages when applicable */ ?>
  75. <?php if (  $wp_query->max_num_pages > 1 ) : ?>
  76.                                 <div id="nav-below" class="navigation">
  77.                                 <?php if(function_exists('wp_pagenavi')) :
  78.  wp_pagenavi();
  79. else : ?>
  80.                                         <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">?</span> Older posts', 'twentyten' ) ); ?></div>
  81.                                         <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">?</span>', 'twentyten' ) ); ?></div>
  82.                                         <?php endif; ?>
  83.                                 </div><!-- #nav-below -->
  84.  
  85. <?php endif;
  86.  wp_reset_query(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement