| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 22 <?php // Display navigation to next/previous pages when applicable. ?> 23 <?php 24 if ( $wp_query->max_num_pages > 1 ) : 25 $is_desc = ( 'DESC' === get_query_var( 'order', 'DESC' ) ); 26 27 $new_posts_text = __( 'Newer posts <span class="meta-nav">→</span>', 'twentyten' ); 28 $old_posts_text = __( '<span class="meta-nav">←</span> Older posts', 'twentyten' ); 29 30 $prev_link = $is_desc ? get_next_posts_link( $old_posts_text ) : get_previous_posts_link( $old_posts_text ); 31 $next_link = $is_desc ? get_previous_posts_link( $new_posts_text ) : get_next_posts_link( $new_posts_text ); 32 ?> 33 <div id="nav-above" class="navigation"> 34 <?php if ( $prev_link ) : ?> 35 <div class="nav-previous"><?php echo $prev_link; ?></div> 36 <?php endif; ?> 37 38 <?php if ( $next_link ) : ?> 39 <div class="nav-next"><?php echo $next_link; ?></div> 40 <?php endif; ?> 41 </div><!-- #nav-above --> 42 <?php endif; ?> 43 44 <?php /* If there are no posts to display, such as an empty archive page */ ?> 45 <?php if ( ! have_posts() ) : ?> 46 <div id="post-0" class="post error404 not-found"> 47 <h1 class="entry-title"><?php _e( 'Not Found', 'twentyten' ); ?></h1> 48 <div class="entry-content"> 49 <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyten' ); ?></p> 50 <?php get_search_form(); ?> 51 </div><!-- .entry-content --> 52 </div><!-- #post-0 --> 53 <?php endif; ?> 54 55 <?php 56 /* 57 * Start the Loop. 58 * 59 * In Twenty Ten we use the same loop in multiple contexts. 60 * It is broken into three main parts: when we're displaying 61 * posts that are in the gallery category, when we're displaying 62 * posts in the asides category, and finally all other posts. 63 * 64 * Additionally, we sometimes check for whether we are on an 65 * archive page, a search page, etc., allowing for small differences 66 * in the loop on each template without actually duplicating 67 * the rest of the loop that is shared. 68 * 69 * Without further ado, the loop: 70 */ 71 ?> 72 <?php 73 while ( have_posts() ) : 74 the_post(); 75 ?> 76 77 <?php /* How to display posts of the Gallery format. The gallery category is the old way. */ ?> 78 79 <?php if ( ( function_exists( 'get_post_format' ) && 'gallery' === get_post_format( $post->ID ) ) || in_category( _x( 'gallery', 'gallery category slug', 'twentyten' ) ) ) : ?> 80 <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 81 <h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2> 82 83 <div class="entry-meta"> 84 <?php twentyten_posted_on(); ?> 85 </div><!-- .entry-meta --> 86 87 <div class="entry-content"> 88 <?php if ( post_password_required() ) : ?> 89 <?php the_content(); ?> 90 <?php else : ?> 91 <?php 92 $images = twentyten_get_gallery_images(); 93 if ( $images ) : 94 $total_images = count( $images ); 95 $image = reset( $images ); 96 ?> 97 <div class="gallery-thumb"> 98 <a class="size-thumbnail" href="<?php the_permalink(); ?>"><?php echo wp_get_attachment_image( $image, 'thumbnail' ); ?></a> 99 </div><!-- .gallery-thumb --> 100 <p><em> 101 <?php 102 printf( 103 /* translators: 1: HTML tag attributes, 2: Image count. */ 104 _n( 'This gallery contains <a %1$s>%2$s photo</a>.', 'This gallery contains <a %1$s>%2$s photos</a>.', $total_images, 'twentyten' ), 105 /* translators: %s: Post title. */ 106 'href="' . esc_url( get_permalink() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ) ) . '" rel="bookmark"', 107 number_format_i18n( $total_images ) 108 ); 109 ?> 110 </em></p> 111 <?php endif; // End twentyten_get_gallery_images() check. ?> 112 <?php the_excerpt(); ?> 113 <?php endif; ?> 114 </div><!-- .entry-content --> 115 116 <div class="entry-utility"> 117 <?php 118 $gallery = get_term_by( 'slug', _x( 'gallery', 'gallery category slug', 'twentyten' ), 'category' ); 119 if ( function_exists( 'get_post_format' ) && 'gallery' === get_post_format( $post->ID ) ) : 120 ?> 121 <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> 122 <span class="meta-sep">|</span> 123 <?php elseif ( $gallery && in_category( $gallery->term_id ) ) : ?> 124 <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> 125 <span class="meta-sep">|</span> 126 <?php endif; ?> 127 <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span> 128 <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 129 </div><!-- .entry-utility --> 130 </div><!-- #post-<?php the_ID(); ?> --> 131 132 <?php /* How to display posts of the Aside format. The asides category is the old way. */ ?> 133 134 <?php elseif ( ( function_exists( 'get_post_format' ) && 'aside' === get_post_format( $post->ID ) ) || in_category( _x( 'asides', 'asides category slug', 'twentyten' ) ) ) : ?> 135 <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 136 137 <?php if ( is_archive() || is_search() ) : // Display excerpts for archives and search. ?> 138 <div class="entry-summary"> 139 <?php the_excerpt(); ?> 140 </div><!-- .entry-summary --> 141 <?php else : ?> 142 <div class="entry-content"> 143 <?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyten' ) ); ?> 144 </div><!-- .entry-content --> 145 <?php endif; ?> 146 147 <div class="entry-utility"> 148 <?php twentyten_posted_on(); ?> 149 <span class="meta-sep">|</span> 150 <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span> 151 <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 152 </div><!-- .entry-utility --> 153 </div><!-- #post-<?php the_ID(); ?> --> 154 155 <?php /* How to display all other posts. */ ?> 156 157 <?php else : ?> 158 <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 159 <h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2> 160 161 <div class="entry-meta"> 162 <?php twentyten_posted_on(); ?> 163 </div><!-- .entry-meta --> 164 165 <?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?> 166 <div class="entry-summary"> 167 <?php the_excerpt(); ?> 168 </div><!-- .entry-summary --> 169 <?php else : ?> 170 <div class="entry-content"> 171 <?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyten' ) ); ?> 172 <?php 173 wp_link_pages( 174 array( 175 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 176 'after' => '</div>', 177 ) 178 ); 179 ?> 180 </div><!-- .entry-content --> 181 <?php endif; ?> 182 183 <div class="entry-utility"> 184 <?php if ( count( get_the_category() ) ) : ?> 185 <span class="cat-links"> 186 <?php 187 /* translators: 1: CSS classes, 2: Category list. */ 188 printf( __( '<span class="%1$s">Posted in</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); 189 ?> 190 </span> 191 <span class="meta-sep">|</span> 192 <?php endif; ?> 193 194 <?php 195 $tags_list = get_the_tag_list( '', ', ' ); 196 if ( $tags_list && ! is_wp_error( $tags_list ) ) : 197 ?> 198 <span class="tag-links"> 199 <?php 200 /* translators: 1: CSS classes, 2: Category list. */ 201 printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); 202 ?> 203 </span> 204 <span class="meta-sep">|</span> 205 <?php endif; ?> 206 207 <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span> 208 209 <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?> 210 </div><!-- .entry-utility --> 211 </div><!-- #post-<?php the_ID(); ?> --> 212 213 <?php comments_template( '', true ); ?> 214 215 <?php endif; // This was the if statement that broke the loop into three parts based on categories. ?> 216 217 <?php endwhile; // End of the loop. Whew. ?> 218 219 <?php // Display navigation to next/previous pages when applicable. ?> 220 <?php if ( $wp_query->max_num_pages > 1 ) : ?> 221 <div id="nav-below" class="navigation"> 222 <?php if ( $prev_link ) : ?> 223 <div class="nav-previous"><?php echo $prev_link; ?></div> 224 <?php endif; ?> 225 226 <?php if ( $next_link ) : ?> 227 <div class="nav-next"><?php echo $next_link; ?></div> 228 <?php endif; ?> 229 </div><!-- #nav-below --> 230 <?php endif; ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Fri May 15 08:20:04 2026 | Cross-referenced by PHPXref |