Undefined variable in my theme
-
Outside the comment loop initialize the variable:
<?php $i=0; ?> <?php if ( have_comments() ) : ?> <!-- Do Comment Block --> <?php $i++; ?><!-- variable for alternating comment styles --> <?php endif; ?>HTH
David
this in the comments.php or in the functions.php?
i just replaced this line
<?php $i++; ?> <!-- variable for alternating comment styles -->and it worked! Thanks Raindrops
What did you replace the line with?
It looks like in comments.php it is using a counter ($i) for swapping styles to make stripes, like in a list where every other line has an different background.
All that was really required was to set the $i variable to 0 before the comment loop!
David
with your code!
or is that wrong?
That way you loose the comments style effect!
Add my code before the comment code block, and add back the original line, and test with several comments.
You should have different styles, it could be the first is different from the others, hard to say without seeing the code.
Or just add the code to pastebin and post a link back.
David
Hi can you pastebin the original file from the theme download and not the modified one?
Cheers
David
sorry!, here is the unmodified one
another question to the same script. How can I style the children of a comments (the replies).
The incremental counter was outside the
foreachloop so the odd and even styles will never happen, I have moved the counter to line 20 and set the ($i=0;) variable at line 13.Use FireFox and FireBug or F12 in Internet Explorer and see if the replies have their on class and modify that in style.css
HTH
David
The topic ‘Undefined variable in my theme’ is closed to new replies.
(@baszer)
15 years ago
Hello,
i got the following error:
and this is line 13 of comments.php
<?php $i++; ?> <!-- variable for alternating comment styles -->how can i fix the error?
thanks in advance