0

I am trying to call in all posts in the current category, showing their thumbnail or 'featured image'. The code below does not work, it throws out a syntax error...

            <?php $temp_query = $wp_query; ?>
            <?php foreach(get_the_category() as $category) {
                $cat = $category->cat_ID; }
                query_posts('orderby=date&cat=' . $cat . '&order=ASC&posts_per_page=-1''); 
            ?>
            <?php while (have_posts()) : the_post(); ?>
                    <div class="page-thumb-wrap-single">
                        <?php
                            if ( has_post_thumbnail() ) {
                                    the_post_thumbnail();
                                } else {
                                        echo '<img src="#" alt="Something Went Wrong?" title="Sorry - Something went wrong?" />';
                            }
                        ?>
                    </div>
            <?php endwhile; ?>

...however, this code does retrieve the thumbnail;

            <?php $temp_query = $wp_query; ?>
            <?php foreach(get_the_category() as $category) {
                $cat = $category->cat_ID; }
                query_posts('orderby=date&cat=' . $cat . '&order=ASC&posts_per_page=-1''); 
            ?>
            <?php while (have_posts()) : the_post(); ?>
                    <div class="page-thumb-wrap-single">
                        <?php the_post_thumbnail(); ?>
                    </div>
            <?php endwhile; ?>

Can someone explain to me what it is i am doing wrong and why this occurs? It may also help me answer another question;

How can i create a condition inside this call to say 'if post has tag... do... if post has other tag... do...'

Thanks guys!

1

the two single quote marks (after the number 1) in this line (of the top posted code section) seem to be causing the error - there should only be one single quote; shown below:

query_posts('orderby=date&cat=' . $cat . '&order=ASC&posts_per_page=-1');  

it is just puzzling that your other code (with the same error) alledegly does work (?)

if this is not the cause: what was the exact syntax error message?

  • That double single quote mark seemed to be making things break - but only with the second code? Not it is corrected, there dont seem to be any errors, so thanks! – Infocentre Jul 15 '11 at 8:28

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.