Echo php statement


#1

Hi,

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 == 'ricky.nelles@gmail.com') { $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?


#2

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

[php]

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

[/php]


#3

So do you mean:

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


#4

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?).


#5

good point :D I thought of that after I posted