WordPress.org

Support

Support » Themes and Templates » Undefined variable in my theme

Undefined variable in my theme

  • Hello,

    i got the following error:

    Notice: Undefined variable: i in /var/www/vhosts/eenwebsitevanbas.nl/subdomains/test/httpdocs/wp-content/themes/bbiotodoma/comments.php on line 13

    and this is line 13 of comments.php
    <?php $i++; ?> <!-- variable for alternating comment styles -->

    how can i fix the error?

    thanks in advance

Viewing 10 replies - 1 through 10 (of 10 total)
  • 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 David,

    would be great if you changed it: http://pastebin.com/5k2bz5h5

    thnx

    Hi can you pastebin the original file from the theme download and not the modified one?

    Cheers

    David

    sorry!, here is the unmodified one

    http://pastebin.com/6dbSunp3

    another question to the same script. How can I style the children of a comments (the replies).

    http://pastebin.com/j85RE1Wc

    The incremental counter was outside the foreach loop 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

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Undefined variable in my theme’ is closed to new replies.
Skip to toolbar