Posts in Three Columns — error in query
-
Apologies for the long post:
I have been using the excellent three column post function developed by Michael (@alchymyth) on several sites.
Here it is formatting properly on a home page of a test site; it also formats properly on search, any taxonomy, etc. (when using those conditional arguments). But it doesn’t format properly when used for a single post with a related query (see here). I’ve also noticed that the formatting doesn’t work properly on a page template with post queries. I think I’ve tried every possible conditional argument, but notice how on the latter example none of the related posts below the single post are assigned the ‘column-post-left’ class. I’m doing something incorrectly, but what?Here are the functions and arguments I’m using below :
functions.php
add_filter('post_class','category_three_column_classes'); function category_three_column_classes( $classes ) { global $wp_query; if( is_post_type_archive('products') || is_tax () || is_home() || is_singular('products') || is_search() || is_page(1689) ) : $classes[] = 'three-column-post'; if( $wp_query->current_post%3 == 0 ) $classes[] = 'column-post-left'; endif; return $classes; }
single-products.php
<div id="primary" class="site-content"> <div id="content" role="main"> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content-products', get_post_type() ); ?> <?php comments_template( '', true ); ?> <?php endwhile; // end of the loop. ?> </div><!-- #content --> </div><!-- #primary --> <div id="primary" class="site-content"> <div id="content" role="main"> <?php $this_post = $post->ID; $args = array( 'post_type' => 'products', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'post__not_in' => array($this_post), ); $terms = get_the_terms($this_post,'region'); if (!is_wp_error($terms)) { $terms = wp_list_pluck($terms,'term_id'); $args['tax_query'] = array( array( 'taxonomy' => 'region', 'field' => 'id', 'terms' => array_values($terms) ) ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { echo '<h1 class="entry-title"> "Related Regional Products" </h1>' . '<br>' . '<br>' ; while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php get_template_part( 'content-archive-long' ); ?> <?php endwhile; } wp_reset_query(); ?> <?php } ?> </div><!-- #content --> </div><!-- #primary --> ' CSS
three-column-post { width: 31.0%; float: left; margin-left: 3.0%; }
.column-post-left { clear: left; margin-left: 0; }`
- The topic ‘Posts in Three Columns — error in query’ is closed to new replies.