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