PageRenderTime 24ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/twentyten/loop.php

http://github.com/wordpress/wordpress
PHP | 208 lines | 150 code | 21 blank | 37 comment | 27 complexity | 57c65d92861ed4f88eb6b743a04f00db MD5 | raw file
Possible License(s): 0BSD
  1. <?php
  2. /**
  3. * The loop that displays posts
  4. *
  5. * The loop displays the posts and the post content. See
  6. * https://developer.wordpress.org/themes/basics/the-loop/ to understand it and
  7. * https://developer.wordpress.org/themes/basics/template-tags/ to understand
  8. * the tags used in it.
  9. *
  10. * This can be overridden in child themes with loop.php or
  11. * loop-template.php, where 'template' is the loop context
  12. * requested by a template. For example, loop-index.php would
  13. * be used if it exists and we ask for the loop with:
  14. * <code>get_template_part( 'loop', 'index' );</code>
  15. *
  16. * @package WordPress
  17. * @subpackage Twenty_Ten
  18. * @since Twenty Ten 1.0
  19. */
  20. ?>
  21. <?php // Display navigation to next/previous pages when applicable. ?>
  22. <?php if ( $wp_query->max_num_pages > 1 ) : ?>
  23. <div id="nav-above" class="navigation">
  24. <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
  25. <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
  26. </div><!-- #nav-above -->
  27. <?php endif; ?>
  28. <?php /* If there are no posts to display, such as an empty archive page */ ?>
  29. <?php if ( ! have_posts() ) : ?>
  30. <div id="post-0" class="post error404 not-found">
  31. <h1 class="entry-title"><?php _e( 'Not Found', 'twentyten' ); ?></h1>
  32. <div class="entry-content">
  33. <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyten' ); ?></p>
  34. <?php get_search_form(); ?>
  35. </div><!-- .entry-content -->
  36. </div><!-- #post-0 -->
  37. <?php endif; ?>
  38. <?php
  39. /*
  40. * Start the Loop.
  41. *
  42. * In Twenty Ten we use the same loop in multiple contexts.
  43. * It is broken into three main parts: when we're displaying
  44. * posts that are in the gallery category, when we're displaying
  45. * posts in the asides category, and finally all other posts.
  46. *
  47. * Additionally, we sometimes check for whether we are on an
  48. * archive page, a search page, etc., allowing for small differences
  49. * in the loop on each template without actually duplicating
  50. * the rest of the loop that is shared.
  51. *
  52. * Without further ado, the loop:
  53. */
  54. ?>
  55. <?php
  56. while ( have_posts() ) :
  57. the_post();
  58. ?>
  59. <?php /* How to display posts of the Gallery format. The gallery category is the old way. */ ?>
  60. <?php if ( ( function_exists( 'get_post_format' ) && 'gallery' == get_post_format( $post->ID ) ) || in_category( _x( 'gallery', 'gallery category slug', 'twentyten' ) ) ) : ?>
  61. <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  62. <h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
  63. <div class="entry-meta">
  64. <?php twentyten_posted_on(); ?>
  65. </div><!-- .entry-meta -->
  66. <div class="entry-content">
  67. <?php if ( post_password_required() ) : ?>
  68. <?php the_content(); ?>
  69. <?php else : ?>
  70. <?php
  71. $images = twentyten_get_gallery_images();
  72. if ( $images ) :
  73. $total_images = count( $images );
  74. $image = reset( $images );
  75. ?>
  76. <div class="gallery-thumb">
  77. <a class="size-thumbnail" href="<?php the_permalink(); ?>"><?php echo wp_get_attachment_image( $image, 'thumbnail' ); ?></a>
  78. </div><!-- .gallery-thumb -->
  79. <p><em>
  80. <?php
  81. printf(
  82. /* translators: 1: HTML tag attributes, 2: Image count. */
  83. _n( 'This gallery contains <a %1$s>%2$s photo</a>.', 'This gallery contains <a %1$s>%2$s photos</a>.', $total_images, 'twentyten' ),
  84. /* translators: %s: Post title. */
  85. 'href="' . esc_url( get_permalink() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ) ) . '" rel="bookmark"',
  86. number_format_i18n( $total_images )
  87. );
  88. ?>
  89. </em></p>
  90. <?php endif; // End twentyten_get_gallery_images() check. ?>
  91. <?php the_excerpt(); ?>
  92. <?php endif; ?>
  93. </div><!-- .entry-content -->
  94. <div class="entry-utility">
  95. <?php
  96. $gallery = get_term_by( 'slug', _x( 'gallery', 'gallery category slug', 'twentyten' ), 'category' );
  97. if ( function_exists( 'get_post_format' ) && 'gallery' == get_post_format( $post->ID ) ) :
  98. ?>
  99. <a href="<?php echo esc_url( get_post_format_link( 'gallery' ) ); ?>" title="<?php esc_attr_e( 'View Galleries', 'twentyten' ); ?>"><?php _e( 'More Galleries', 'twentyten' ); ?></a>
  100. <span class="meta-sep">|</span>
  101. <?php elseif ( $gallery && in_category( $gallery->term_id ) ) : ?>
  102. <a href="<?php echo esc_url( get_category_link( $gallery ) ); ?>" title="<?php esc_attr_e( 'View posts in the Gallery category', 'twentyten' ); ?>"><?php _e( 'More Galleries', 'twentyten' ); ?></a>
  103. <span class="meta-sep">|</span>
  104. <?php endif; ?>
  105. <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>
  106. <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
  107. </div><!-- .entry-utility -->
  108. </div><!-- #post-<?php the_ID(); ?> -->
  109. <?php /* How to display posts of the Aside format. The asides category is the old way. */ ?>
  110. <?php elseif ( ( function_exists( 'get_post_format' ) && 'aside' == get_post_format( $post->ID ) ) || in_category( _x( 'asides', 'asides category slug', 'twentyten' ) ) ) : ?>
  111. <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  112. <?php if ( is_archive() || is_search() ) : // Display excerpts for archives and search. ?>
  113. <div class="entry-summary">
  114. <?php the_excerpt(); ?>
  115. </div><!-- .entry-summary -->
  116. <?php else : ?>
  117. <div class="entry-content">
  118. <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
  119. </div><!-- .entry-content -->
  120. <?php endif; ?>
  121. <div class="entry-utility">
  122. <?php twentyten_posted_on(); ?>
  123. <span class="meta-sep">|</span>
  124. <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>
  125. <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
  126. </div><!-- .entry-utility -->
  127. </div><!-- #post-<?php the_ID(); ?> -->
  128. <?php /* How to display all other posts. */ ?>
  129. <?php else : ?>
  130. <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  131. <h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
  132. <div class="entry-meta">
  133. <?php twentyten_posted_on(); ?>
  134. </div><!-- .entry-meta -->
  135. <?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
  136. <div class="entry-summary">
  137. <?php the_excerpt(); ?>
  138. </div><!-- .entry-summary -->
  139. <?php else : ?>
  140. <div class="entry-content">
  141. <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
  142. <?php
  143. wp_link_pages(
  144. array(
  145. 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ),
  146. 'after' => '</div>',
  147. )
  148. );
  149. ?>
  150. </div><!-- .entry-content -->
  151. <?php endif; ?>
  152. <div class="entry-utility">
  153. <?php if ( count( get_the_category() ) ) : ?>
  154. <span class="cat-links">
  155. <?php
  156. /* translators: 1: CSS classes, 2: Category list. */
  157. printf( __( '<span class="%1$s">Posted in</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) );
  158. ?>
  159. </span>
  160. <span class="meta-sep">|</span>
  161. <?php endif; ?>
  162. <?php
  163. $tags_list = get_the_tag_list( '', ', ' );
  164. if ( $tags_list ) :
  165. ?>
  166. <span class="tag-links">
  167. <?php
  168. /* translators: 1: CSS classes, 2: Category list. */
  169. printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list );
  170. ?>
  171. </span>
  172. <span class="meta-sep">|</span>
  173. <?php endif; ?>
  174. <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>
  175. <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
  176. </div><!-- .entry-utility -->
  177. </div><!-- #post-<?php the_ID(); ?> -->
  178. <?php comments_template( '', true ); ?>
  179. <?php endif; // This was the if statement that broke the loop into three parts based on categories. ?>
  180. <?php endwhile; // End of the loop. Whew. ?>
  181. <?php // Display navigation to next/previous pages when applicable. ?>
  182. <?php if ( $wp_query->max_num_pages > 1 ) : ?>
  183. <div id="nav-below" class="navigation">
  184. <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
  185. <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
  186. </div><!-- #nav-below -->
  187. <?php endif; ?>