0

I've simple question regarding WordPress post looping.

I want to achieve something like this on my site: ~ I am running Real estate portal site and I want to display featured property on my home page with custom layout. IN this custom layout I want to have six division each will hold slider which contains six featured property in it. so there will be total of 36 featured property on home page, In wordpress we can retrieved featured property by looping but I want to place them separately in each division one by one. Like first property in first division and second in second division and so on. when All six divisions fill with single property then again start with first division and add extra property in it and again repeat the process. Is it possible to do so?

If so then can you show me he way

0

Yes, it is quite simple, you just need to work in PHP.

Consider you have 36 posts in a loop.

$div_html_1 = '';    
$div_html_2 = '';    
$div_html_3 = '';    
$div_html_4 = '';    
$div_html_5 = '';    
$div_html_6 = '';


if ( have_posts() ) {
    while ( have_posts() ) {
        if( category of post == division 1 ) {
            $div_html_1 .= "Your HTML here";
        } elseif( category of post == division 2 ) {
            $div_html_2 .= "Your HTML here";
        }
        and so on....
    }
}

And in the layout, your code would be like,

<div id="prefix_div_one">
    <?php echo $div_html_1; ?>
</div>
<div id="prefix_div_two">
    <?php echo $div_html_2; ?>
</div>

and so on...
  • Thanks for the answer it looks quite convincing but what if all posts are from same category ? – Vijay Jun 17 '15 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.