Echo php statement


I have a php statement that marks each comment either “Comment” or “commentalt” (Wordpress comment template)

I also have another function that checks to see if the poster was the admin:

<?php $isByAuthor = false; if($comment->comment_author_email == '[email protected]') { $isByAuthor = true;} ?>

I want to be able to echo different list classes and ids based on the status of those two functions.

I am using this:

<?php if($isByAuthor ) { echo'<li class="commentadmin" id="comment">';} else { echo '<li class="comment<?php echo $oddcomment; ?>" id="comment-<?php comment_ID() ?>">';} ?>

but it doesn’t then run that php, it just outputs what is written there. Is there any way to output the php with that function above?

You cannot open PHP tags inside PHP code (afaik). Take those out and echo the values of the variables outside the single quotes:


<?php echo 'Some text' . $variable . 'some more text'; ?>


So do you mean:

echo '<li class="comment' .<?php echo $oddcomment; ?>. '" id="comment-' . <?php comment_ID() ?>">';} ?>.'

Yep, that’s where I presume things go wrong. Once you’re in PHP mode, you don’t have to open PHP tags again (makes sense, right?).

good point :D I thought of that after I posted

Sponsor our Newsletter | Privacy Policy | Terms of Service