WordPress.org

Ready to get started?Download WordPress

Forums

do conditional tags work inside the loop? (6 posts)

  1. notthatugly
    Member
    Posted 9 years ago #

    My adventures in trying to create different templates for daily and monthly archives continue... Today I am having difficulty getting is_day and is_month to work within the loop without throwing up parse errors. Are they even supposed to work within the loop? Should I be putting the loop inside the conditional statements? Should I give up and try again when I'm less rubbish at PHP?

  2. Kafkaesqui

    Posted 9 years ago #

    I've five different if statements in The Loop of my main index.php that make use of the conditionals, all without problem. Would help in debugging to know what the errors are you're seeing.

    And we're all about rubbish here!

  3. notthatugly
    Member
    Posted 9 years ago #

    Thanks, I should be ok now I've found some sample code to work from. Basically I had no idea how to use functions inside an echo, and that's what was causing the difficulties.

    (Please consider adding your example of use within the loop to the codex! There may be others like me who assume from the current page that conditional tags are designed exclusively for sidebars.)

  4. Kafkaesqui

    Posted 9 years ago #

    "Please consider adding your example of use within the loop to the codex!"

    Will do.

  5. notthatugly
    Member
    Posted 9 years ago #

    Once more I have overestimated my abilities and cannot, in fact, get the sample code to work either. I get a 'Parse error: unexpected <' the line after the conditionals end.
    To my eye it looks slightly odd that there's no closing ?> to finish off the conditional statements, but maybe that's how it's supposed to be? In any case, when I add one I get 'unexpected $end' on the last line of the template.

    That'll teach me for trying to show off. I just wish month.php had existed after all, it would have saved me a lot of frustration.

  6. Kafkaesqui

    Posted 9 years ago #

    The example code on Codex did have a missing closing PHP tag. I've corrected it.

    Showing off is still acceptable...

Topic Closed

This topic has been closed to new replies.

About this Topic