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'm trying to minimize my code and have put together this little snippet, it doesn't seem to work however. What am I missing?

query_posts( 'year=2011' );
if ( have_posts() );
while ( have_posts() );
echo 'test';
endwhile;
wp_reset_query();
endif;
share|improve this question

closed as too localized by toscho May 17 '13 at 17:18

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Perhaps "shortcodes" is not the right word for it. I meant leaving out in this case the curly brackets in the if and while statements. What is the word for optimizing like this? :) –  Staffan Estberg Sep 28 '11 at 12:51
    
This has nothing to do with shortcodes... –  AlxVallejo Jun 20 '12 at 17:09
1  
It's just referred to as an alternative syntax for loops. –  Ian Dunn Sep 14 '12 at 1:15
    
Closing voting as off-topic as this is a simple PHP syntax error. –  Brian Fegter Sep 14 '12 at 3:51

1 Answer 1

up vote 2 down vote accepted

Because you're using semicolons when you should be using colons after the if and the while :)

query_posts( 'year=2011' );
if ( have_posts() ):
    while ( have_posts() ):
        the_post();
        the_title();
    endwhile;
    wp_reset_query();
endif;

That works just fine.

share|improve this answer
    
Worked perfectly, thanks! –  Staffan Estberg Sep 28 '11 at 12:48

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