-
-
Save davidvandenbor/5be5f15dd888bcd3fba1 to your computer and use it in GitHub Desktop.
WordPress: Loops
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php /* Simple alter main loop ------------------------------------------*/ ?> | |
| <?php query_posts('posts_per_page=1&post_type=locations'); ?> | |
| <?php if(have_posts()) while (have_posts()) : the_post(); ?> | |
| <h1><?php the_title(); ?></h1> | |
| <?php the_content('read more...'); ?> | |
| <?php endwhile; ?> | |
| <?php wp_reset_query(); ?> | |
| <?php /* Simple create multiple loops ------------------------------------------*/ ?> | |
| <?php | |
| global $post; | |
| $args = array( 'numberposts' => 5 ); | |
| $myposts = get_posts( $args ); | |
| foreach( $myposts as $post ) : setup_postdata($post); | |
| ?> | |
| <h1><?php the_title(); ?></h1> | |
| <?php endforeach; ?> | |
| <?php /* Multiple loops with pagination ------------------------------------------*/ ?> | |
| <?php | |
| // sidebar fix | |
| global $paged; | |
| // home page fix | |
| if ( get_query_var('paged') ) $paged = get_query_var('paged'); | |
| else if ( get_query_var('page') ) $paged = get_query_var('page'); | |
| else $paged = 1; | |
| $ppp = get_option('posts_per_page'); | |
| $tmp = $wp_query; | |
| $wp_query = null; | |
| $wp_query = new WP_Query(array( 'numberposts' => 5 )); | |
| while ( $wp_query->have_posts() ) : $wp_query->the_post(); | |
| ?> | |
| <h1><?php the_title(); ?></h1> | |
| <?php endwhile; ?> | |
| <?php // previous_posts_link('← Previous Post'); next_posts_link('Next Post →'); ?> | |
| <?php | |
| wp_pagenavi( array( 'query' => $wp_query ) ); | |
| $wp_query = null; | |
| $wp_query = $tmp; | |
| ?> | |
| <?php /* Various Looping-related fixes ------------------------------------------*/ ?> | |
| <?php | |
| /** | |
| * Use 'read more' in a post listing on a page | |
| * See: http://codex.wordpress.org/Customizing_the_Read_More#How_to_use_Read_More_in_Pages | |
| */ | |
| ?> | |
| <?php | |
| global $more; | |
| query_posts('posts_per_page=1&post_type=locations'); | |
| $more=0; | |
| // ... | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment