WooCommerce Product Page Loop – Output All Product Thumbnails

The second parameter on get_the_post_thumbnail takes the size of the image you want. You’re currently passing in: apply_filters( ‘single_product_large_thumbnail_size’, ‘shop_single’ ) but change that to apply_filters( ‘single_product_small_thumbnail_size’, ‘shop_thumbnail’ ) And you’ll have the smaller image size. You can also pass in “thumbnail” or any of the custom sizes you have in that spot without the … Read more

Identify which loop you are hooking into; primary or secondary?

Just a quick update that a new method is_main_query() has been introduced in WP 3.3. Example: add_action( ‘pre_get_posts’, ‘foo_modify_query_exclude_category’ ); function foo_modify_query_exclude_category( $query ) { if ( $query->is_main_query() && ! $query->get( ‘cat’ ) ) $query->set( ‘cat’, ‘-5’ ); } Resources: WPDevel: New API in 3.3: is_main_query() Codex reference: is_main_query() Related Trac Ticket #18677

Reverse chronology of post listing

You can add code below to the beginning of loop.php add_action(‘pre_get_posts’, ‘wpse_change_post_order’); function wpse_change_post_order($query){ $query->set(‘order’,’ASC’); $query->set(‘orderby’,’date’); } the oldest posts will be in the home page.

Grab the first paragraph of each post

You can use this function: function get_first_paragraph(){ global $post; $str = wpautop( get_the_content() ); $str = substr( $str, 0, strpos( $str, ‘</p>’ ) + 4 ); $str = strip_tags($str, ‘<a><strong><em>’); return ‘<p>’ . $str . ‘</p>’; } and then call it in your loop with: <?php echo get_first_paragraph(); ?> The magic part your looking for … Read more

Pagination with 5 posts per page

This is working for me on a single page using a template. Just be sure to set next_posts_link( ‘Older Entries »’, $the_query->max_num_pages );. // set the “paged” parameter (use ‘page’ if the query is on a static front page) $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : ‘1’; $args = array … Read more

Loop through all tags & output posts in alphabetical list

(Untested) but should works with any taxonomy including the ‘tag’ taxonomy (post_tag). The following example uses the taxonomy with name ‘my-taxonomy’. <?php //Get terms for this taxonomy – orders by name ASC by default $terms = get_terms(‘my-taxonomy’); //Loop through each term foreach($terms as $term): //Query posts by term. $args = array( ‘orderby’ => ‘title’, //As … Read more