• Resolved pgb

    (@pgb)


    In a page template I’m looking to have some tables with alternate stripes. Javascript doesn’t work. Does anyone know of some php to do this and where to enter it in my template?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Please provide some more information and possibly the url of the site so that we can understand exactly what you attempting.

    are you building the table within the post or page or is this a piece of meta that you are trying to fill. this will decide what you can and can’t do.

    Thread Starter pgb

    (@pgb)

    Thanks. I am working locally at the moment, so no url, sorry. I have a page template and want to have any amount of tables on any pages that use the template. I want every other tr to have a different color (stripes). Javascript doesn’t work. I could use html and css classes which will get tedious with long tables. Is there any php which could cover this and where should I insert it in the template?

    $x=1;
    while(...){
     if($x%2) $alt=' class="alt"';
     else $alt='';
     echo '<tr'.$alt.'>'
     ...
     $x++;
    }

    Hi pgb,
    I answered a topic the other day, which is almost what you want, as someone wanted a list like the forum posts here.

    It is the same concept as the reply from Rich, but has a working example as a ‘twenty ten’ child theme.

    There is a download, which is a child theme for twenty ten (3 files), inside the download there is the loop-index.php which has the code change.

    Or the code is here: lines 40 to 45, all it does is MOD counter and add a background style to the post element.

    Inside the loop change alternate backgrounds:

    <?php $counter++; $style=""; ?>
    <?php if($counter % 2) $style='style="background-color: #f5f5f5";'; ?>
    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?> <?php echo $style; ?> >

    HTH

    David

    Thread Starter pgb

    (@pgb)

    Thanks very much, I’ll give it a try.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘php code instead of javascript for stripey tables’ is closed to new replies.