Hiya Guys! so I need some help with this:


        $newsposts = new WP_Query('cat=restaurant');

        if ( is_front_page()) { echo '<h3 class="member-review">Latest Restaurants</h3>

        <div id="extra">if ($newsposts->have_posts()) : while ($newsposts->have_posts()) : $newsposts->the_post();

        <div class="reslogo"><img src="'echo catch_that_image()' /></div>

        endwhile, endif; 


        } ?>

What I'm trying to do here is have an image slider of first post images (from restaurant category) display at the bottom of the page. I use DIVs to control placement/ style but I really need help with my PHP syntax ... I just cant figure it out... Any help would be greatly appreciated!


2 Answers 2


you can't run code inside quote since php treats it as string, try this:

    $newsposts = new WP_Query('cat=restaurant');
    if ( is_front_page()) { 
        echo '<h3 class="member-review">Latest Restaurants</h3>
        <div id="extra">';
        if ($newsposts->have_posts()) : while ($newsposts->have_posts()) : $newsposts->the_post();
            echo '<div class="reslogo"><img src="'.catch_that_image().'"/></div>';
        endwhile, endif; 
        echo '</div>';    
  • Hey man thank you for your suggestion I tried both approaches and found yours worked exactly as I needed - just needed to replace the endwhile, endif; with endwhile; endif; one of these cats (;) you guys are great I really enjoy learning code and its so awesome that there are people like you out there helping guys like me ;) Cheers - ave a great sunday!
    – brett
    Apr 3, 2011 at 14:04
  • Glad i could help.
    – Bainternet
    Apr 3, 2011 at 14:06
  • Hi there, Is there a way that I can limit the amount of posts being displayed? - I'd just like to have seven. I've tried this: code<?php $newsposts = new WP_Query('cat=restaurant'.'limit=7'); if ( is_front_page()) { echo '<h3 class="member-review">Latest Restaurants</h3> <div id="homeslider">'; if ($newsposts->have_posts()) : while ($newsposts->have_posts()) : $newsposts->the_post(); echo '<div class="reslogohome"><img src="'.catch_that_image().'"/></div>'; endwhile; endif; echo '</div>';} ?>code
    – brett
    Apr 4, 2011 at 6:57

I would suggest a totally different syntactic approach: instead of echoing HTML from PHP, insert PHP calculated values inside HTML. This makes the code more organized and readable.

<?php $newsposts = new WP_Query('cat=restaurant'); ?>

<?php if ( is_front_page()): ?>
<h3 class="member-review">Latest Restaurants</h3>

<div id="extra">
    <?php if ($newsposts->have_posts()): ?>
        <?php while ($newsposts->have_posts()) : $newsposts->the_post(); ?>

        <div class="reslogo"><img src="<?php echo catch_that_image() ?>" /></div>

        <?php endwhile; ?>
    <?php endif; ?>

Note: I don't know if this code is correct, I just updated the syntax.

  • Thank you for having a look and I really liked your suggestion. Especially in your approach to the code. I appreciate your time! Have a super sunday
    – brett
    Apr 3, 2011 at 14:03

Your Answer

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

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