Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've got to display 6 boxes on the homepage of a site I'm working on and struggling with the code. I've managed to get this far:

<?php 
$term = get_term( hotelCategoryID, 'accommodation-category' );
$output = '<div class="box"> ';
if (function_exists('get_terms_meta'))
{
     $category_hotel = get_terms_meta(hotelCategoryID, 'image_taxonomy',true);

}
if($category_hotel ) : 
$output .= '<img src="'.$category_hotel.'" width="300" alt="'.$term->name.'" />';
endif;
$output .= '<div class="textbox"> 
                <em class="corner">corner</em>
                <h2>'.$term->name.'</h2>'.
                $term->description.'
            </div>';?>
<?php 
 $args = array('post_type' => 'accommodation','tax_query' => array( array('taxonomy' => 'accommodation-category','field' => 'id','terms' => hotelCategoryID)));
query_posts($args);?>
<?php if (have_posts()) : $count_post = 0;
    $output .= '<div class="list-area"><ul>';
   while (have_posts()) : the_post();
 if($count_post==5) $output .='</ul><ul class="list">';
 $count_post++;
 $output .= '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
 endwhile;
 $output .= '</ul>
    <div class="opener-holder">
        <a class="opener" href="#"><span>+&nbsp;&nbsp; MORE '.$term->name.'</span><em>-&nbsp;&nbsp; LESS '.$term->name.'</em></a> 
    </div>
</div>';
endif; wp_reset_query();
$output .= '</div>';?>

But when I copy the code and modify it to get the information from another custom post type it just displays one block on the homepage, I assume it's an issue with the loop in this code. I've tried various other codes but this is the one that I need as it has "5" highlighted posts, and then the rest aren't.

Could someone give me an idea on how to edit the loop so I can display 6 of these on one page please?

Thanks!

share|improve this question

1 Answer 1

Hard to say without a little more detail or seeing the entire page's code, but I'm going to wage that your issue is $output = '<div class="box"> ';. If you're repeating that line before echo or printing $output, then you're losing the value of $output. If that's the issue, change this line to $output .= '<div class="box"> '; and at the very top of the page, add $output = '';

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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