Error in php code

Hi Everyone!
I’m facing a error in php program
I have this basic code which outputs my WordPress blog posts in 4 columns going across.

<?php while ( have_posts() ) : the_post(); ?>
       <?php
		$args = array(
				'post_type'      => 'post',
				'posts_per_page' => - 1,
			);
			$q    = new WP_Query( $args );
		?>

		<div class="row">
			<?php while ( $q->have_posts() ) : $q->the_post(); ?>
				<div class="col-6">
					<h3>
						<a href="<?php the_permalink(); ?>">
							<?php the_title(); ?>
						</a>
					</h3>
					<?php the_excerpt(); ?>
				</div>
			<?php endwhile; ?>
			<?php wp_reset_postdata(); ?>
		</div>

	<?php endwhile; ?>

What I would like to do is have two large ones on the left with 4 other ones to the right.

What would be the best way to do this?

Thanks!

When you say “error”, do you mean that it gives an error message or somehow doesn’t work, or that it just doesn’t do what you want it to do? What have you tried to make it work how you want it?

“2 large ones on the left with 4 other ones on the right”… so… 4-4-1-1-1-1.

Right now, your code says to have 2 big columns. (Bootstrap’s grid is 12 units wide; saying “col-6” means “make me a column that takes up 50% of the width”)

Start a counter outside your while loop at 0. if counter % 6 < 2, give the div col-4. Else, give it col-1. Then add 1 to the counter.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.