Advertisement
vtxyzzy

loop-home.php for short front page

May 20th, 2012
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.41 KB | None | 0 0
  1. <?php
  2. /**
  3.  * loop-home.php
  4.  *
  5.  * Used to display a short home page in a TwentyTen child theme.
  6.  *
  7.  *
  8.  *
  9.  */
  10. ?><!-- file:loop-home.php -->
  11. <?php
  12. $max_first_page = 3;  // Show this many posts on front page
  13. $args = $wp_query->query;
  14. $args['caller_get_posts'] = 1; // Using stickies messes up the count
  15. $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
  16. $posts_per_page = get_query_var('posts_per_page');
  17. $posts_to_skip = $posts_per_page - $max_first_page;
  18. if ($page == 1) {
  19.    $max_posts = $max_first_page;
  20. } else {
  21.    $max_posts = $posts_per_page;
  22.    $args['offset'] = (($page - 1) * $max_posts)- $posts_to_skip;
  23. }
  24. query_posts($args);
  25. if ($wp_query->max_num_pages < ceil(($wp_query->found_posts + $posts_to_skip)/$posts_per_page))
  26.   ++$wp_query->max_num_pages;
  27. $counter = 0;
  28. ?>
  29.  
  30.  
  31. <?php /* Display navigation to next/previous pages when applicable */ ?>
  32. <?php if ( $wp_query->max_num_pages > 1 ) : ?>
  33.    <div id="nav-above" class="navigation">
  34.       <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
  35.       <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
  36.    </div><!-- #nav-above -->
  37. <?php endif; ?>
  38.  
  39. <?php /* If there are no posts to display, such as an empty archive page */ ?>
  40. <?php if ( ! have_posts() ) : ?>
  41.    <div id="post-0" class="post error404 not-found">
  42.       <h1 class="entry-title"><?php _e( 'Not Found', 'twentyten' ); ?></h1>
  43.       <div class="entry-content">
  44.          <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyten' ); ?></p>
  45.          <?php get_search_form(); ?>
  46.       </div><!-- .entry-content -->
  47.    </div><!-- #post-0 -->
  48. <?php endif; ?>
  49.  
  50. <?php /* Start the Loop. */ ?>
  51. <?php while ( have_posts() ) : the_post(); ?>
  52.    <?php if (++$counter > $max_posts) continue; ?>
  53. <?php /* How to display posts of the Gallery format. The gallery category is the old way. */ ?>
  54.  
  55.    <?php if ( ( function_exists( 'get_post_format' ) && 'gallery' == get_post_format( $post->ID ) ) || in_category( _x( 'gallery', 'gallery category slug', 'twentyten' ) ) ) : ?>
  56.       <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  57.          <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
  58.  
  59.          <div class="entry-meta">
  60.             <?php twentyten_posted_on(); ?>
  61.          </div><!-- .entry-meta -->
  62.  
  63.          <div class="entry-content">
  64. <?php if ( post_password_required() ) : ?>
  65.             <?php the_content(); ?>
  66. <?php else : ?>
  67.             <?php
  68.                $images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
  69.                if ( $images ) :
  70.                   $total_images = count( $images );
  71.                   $image = array_shift( $images );
  72.                   $image_img_tag = wp_get_attachment_image( $image->ID, 'thumbnail' );
  73.             ?>
  74.                   <div class="gallery-thumb">
  75.                      <a class="size-thumbnail" href="<?php the_permalink(); ?>"><?php echo $image_img_tag; ?></a>
  76.                   </div><!-- .gallery-thumb -->
  77.                   <p><em><?php printf( _n( 'This gallery contains <a %1$s>%2$s photo</a>.', 'This gallery contains <a %1$s>%2$s photos</a>.', $total_images, 'twentyten' ),
  78.                         'href="' . get_permalink() . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark"',
  79.                         number_format_i18n( $total_images )
  80.                      ); ?></em></p>
  81.             <?php endif; ?>
  82.                   <?php the_excerpt(); ?>
  83. <?php endif; ?>
  84.          </div><!-- .entry-content -->
  85.  
  86.          <div class="entry-utility">
  87.          <?php if ( function_exists( 'get_post_format' ) && 'gallery' == get_post_format( $post->ID ) ) : ?>
  88.             <a href="<?php echo get_post_format_link( 'gallery' ); ?>" title="<?php esc_attr_e( 'View Galleries', 'twentyten' ); ?>"><?php _e( 'More Galleries', 'twentyten' ); ?></a>
  89.             <span class="meta-sep">|</span>
  90.          <?php elseif ( in_category( _x( 'gallery', 'gallery category slug', 'twentyten' ) ) ) : ?>
  91.             <a href="<?php echo get_term_link( _x( 'gallery', 'gallery category slug', 'twentyten' ), 'category' ); ?>" title="<?php esc_attr_e( 'View posts in the Gallery category', 'twentyten' ); ?>"><?php _e( 'More Galleries', 'twentyten' ); ?></a>
  92.             <span class="meta-sep">|</span>
  93.          <?php endif; ?>
  94.             <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>
  95.             <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
  96.          </div><!-- .entry-utility -->
  97.       </div><!-- #post-## -->
  98.  
  99. <?php /* How to display posts of the Aside format. The asides category is the old way. */ ?>
  100.  
  101.    <?php elseif ( ( function_exists( 'get_post_format' ) && 'aside' == get_post_format( $post->ID ) ) || in_category( _x( 'asides', 'asides category slug', 'twentyten' ) )  ) : ?>
  102.       <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  103.  
  104.       <?php if ( is_archive() || is_search() ) : // Display excerpts for archives and search. ?>
  105.          <div class="entry-summary">
  106.             <?php the_excerpt(); ?>
  107.          </div><!-- .entry-summary -->
  108.       <?php else : ?>
  109.          <div class="entry-content">
  110.             <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
  111.          </div><!-- .entry-content -->
  112.       <?php endif; ?>
  113.  
  114.          <div class="entry-utility">
  115.             <?php twentyten_posted_on(); ?>
  116.             <span class="meta-sep">|</span>
  117.             <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>
  118.             <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
  119.          </div><!-- .entry-utility -->
  120.       </div><!-- #post-## -->
  121.  
  122. <?php /* How to display all other posts. */ ?>
  123.  
  124.    <?php else : ?>
  125.       <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  126.          <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
  127.  
  128.          <div class="entry-meta">
  129.             <?php twentyten_posted_on(); ?>
  130.          </div><!-- .entry-meta -->
  131.  
  132.    <?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
  133.          <div class="entry-summary">
  134.             <?php the_excerpt(); ?>
  135.          </div><!-- .entry-summary -->
  136.    <?php else : ?>
  137.          <div class="entry-content">
  138.             <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
  139.             <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
  140.          </div><!-- .entry-content -->
  141.    <?php endif; ?>
  142.  
  143.          <div class="entry-utility">
  144.             <?php if ( count( get_the_category() ) ) : ?>
  145.                <span class="cat-links">
  146.                   <?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?>
  147.                </span>
  148.                <span class="meta-sep">|</span>
  149.             <?php endif; ?>
  150.             <?php
  151.                $tags_list = get_the_tag_list( '', ', ' );
  152.                if ( $tags_list ):
  153.             ?>
  154.                <span class="tag-links">
  155.                   <?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?>
  156.                </span>
  157.                <span class="meta-sep">|</span>
  158.             <?php endif; ?>
  159.             <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>
  160.             <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
  161.          </div><!-- .entry-utility -->
  162.       </div><!-- #post-## -->
  163.  
  164.       <?php comments_template( '', true ); ?>
  165.  
  166.    <?php endif; // This was the if statement that broke the loop into three parts based on categories. ?>
  167.  
  168. <?php endwhile; // End the loop. Whew. ?>
  169.  
  170. <?php /* Display navigation to next/previous pages when applicable */ ?>
  171. <?php if (  $wp_query->max_num_pages > 1 ) : ?>
  172.             <div id="nav-below" class="navigation">
  173.                <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
  174.                <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
  175.             </div><!-- #nav-below -->
  176. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement