Loop through pages with specific template

WordPress saves page templates that is assigned to a specific page in the db in the wp_postmeta table. These are saved as follows: ‘meta_key’ => ‘_wp_page_template’, ‘meta_value’ => ‘NAME_ OF_TEMPLATE’ With this in mind, you can loop through pages which shares a specific page template, using get_pages (You can also make use of WP_Query) Example: … Read more

Loop through all posts in a certain year

You will have to run a custom query for that. Here is the query for displaying posts from a particular year. I have used year 2012 as an example. $args = array( ‘post_type’ => ‘post’, ‘ignore_sticky_posts’ => 1, ‘year’ => ‘2012’, ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( … Read more

How to get to a specific position in wp_query?

I think instead of using PHP rand you’re better off limiting ( if you need to ) using posts_per_page and then getting a random set using orderby => ‘rand’. Full List of Ordering Parameters So if I were to edit your query it would look like this: $args = array( ‘post_type’ => ‘attachment’, ‘meta_key’ => … Read more

Style first 3 posts differently with a container, then the rest of the posts [closed]

As Milo noted, the final result might look something like the following if ($wp_query->have_posts()) { while ($wp_query->have_posts()) { $wp_query->the_post(); $post_title = get_the_title(); # On the first pass, write the start of your single container if ( 0 == $wp_query->current_post ) { echo ‘<div class=”container”>’; } echo <<<HTML <div class=”different-post-style”> {$the_title} </div> HTML; # On the … Read more