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:

$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.'" />';
$output .= '<div class="textbox"> 
                <em class="corner">corner</em>
 $args = array('post_type' => 'accommodation','tax_query' => array( array('taxonomy' => 'accommodation-category','field' => 'id','terms' => hotelCategoryID)));
<?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">';
 $output .= '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
 $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> 
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?


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 = '';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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