• Hi,

    I am creating a full screen portfolio page within wordpress. I have the code working manually and am now about to put it into a wordpress template and pull the items from a post category. My question is how can I only show posts in multiples of 4 e.g. 4,8,12,16,20,24,28,32

    The portfolio section has 4 items to each row and I do not want to have a blank square. If this is not possible I think the only way would be to limit it to a fixed number of posts. If I do this is it possible to display the posts randomly rather than in an order?

    Any advice would be appreciated.

    Thanks
    Ben

Viewing 2 replies - 1 through 2 (of 2 total)
  • I don’t think I understand… how would showing 4 in multiples of 4 cause a blank square?

    Do you have a link to you site showing what’s there?

    You should be using the Loop to loop through posts. See also, retrieving posts with WP_Query.

    So if you’re doing that, you can set a variable before the loop starts:

    <?php $i = 0; ?>

    And increment that variable just before the end of the loop:

    <?php $i++ ?>

    Then, inside the loop, you can check if this is the first post in a group of 4. If so, then create a new row:

    <?php
    if ( 0 === $i % 4 ) {
        // output html to start a new row
    }
    ?>

    And you can use the same technique to end a row.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show posts in groups of 4’ is closed to new replies.