WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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';
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
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
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() ):

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.