I got a loop from internet (I forgot the site) for two column post view. It has a nice CSS for it too. But skipping that for the question now.
<?php $counter = 1; ?>
<?php query_posts( 'cat=3&showposts=6' ); //Find whether the catID is 3 ?>
<?php while ( have_posts() ) : the_post() ?>
<?php /* Two Column Support get class */ ?>
<?php $class = ( $counter % 2 ? ' one' : '' ) ?>
<?php /* Two Column output open the div class */ ?>
<div class="column<?php echo $class;// echo $first; ?>">
<?php news_format(); ?>
</div> <!-- End Two Column Support close div class -->
<?php $counter++; //Update counter ?>
It printed my posts into 2 columns like:
========= | 1 | 2 | --------- | 3 | 4 | --------- | 5 | 6 | =========
It’s fine.
But I want to print it like this:
========= | 1 | --------- | 2 | 3 | --------- | 4 | 5 | --------- | 6 | 7 | =========
What the modification I need to do?
I can’t pass any custom limit into the WordPress’ custom loop <?php while ( have_posts() ) : the_post() ?>
. It’s for a custom theme. I did it, but the problem is, it’s showing like:
========= | 1 | --------- | 1 | 2 | --------- | 3 | 4 | --------- | 5 | 6 | =========
Here is my whole bunch of code.
Add a last test for
1 === $counter
. And put that into a function in your themeâsfunctions.php
like this:Now in the loop you just call that function where you need it:
You are allowed to use line breaks in PHP code. And space wherever it helps readability. 😉
And I recommend not to use
query_posts()
. Read: When should you use WP_Query vs query_posts() vs get_posts()?