WordPress.org

Ready to get started?Download WordPress

Forums

Undefined variable in my theme (11 posts)

  1. baszer
    Member
    Posted 3 years ago #

    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

  2. Digital Raindrops
    Member
    Posted 3 years ago #

    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

  3. baszer
    Member
    Posted 3 years ago #

    this in the comments.php or in the functions.php?

  4. baszer
    Member
    Posted 3 years ago #

    i just replaced this line

    <?php $i++; ?> <!-- variable for alternating comment styles -->

    and it worked! Thanks Raindrops

  5. Digital Raindrops
    Member
    Posted 3 years ago #

    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

  6. baszer
    Member
    Posted 3 years ago #

    with your code!

    or is that wrong?

  7. Digital Raindrops
    Member
    Posted 3 years ago #

    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

  8. baszer
    Member
    Posted 3 years ago #

    Hi David,

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

    thnx

  9. Digital Raindrops
    Member
    Posted 3 years ago #

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

    Cheers

    David

  10. baszer
    Member
    Posted 3 years ago #

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

  11. Digital Raindrops
    Member
    Posted 3 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic