Skip to content

Instantly share code, notes, and snippets.

@FreshLondon
Created December 1, 2020 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FreshLondon/be700f64700030fb61c1febf91b49fff to your computer and use it in GitHub Desktop.
Save FreshLondon/be700f64700030fb61c1febf91b49fff to your computer and use it in GitHub Desktop.
<?
// I'd like to see whether the task row is odd or even in CSS for printing
// as for PHP DomPDF I cant use pseudo classes (:nth-child(odd))
// get the tasks
$tasks = json_decode(get_post_meta($post->ID, 'tasks', true), true);
// set an evenm starting point, eg 0
$row_oddEven = 10;
//loop through each task
foreach ($tasks as $task) {
// add 1 to the current odd/even number
$row_oddEven++;
// clear the previous odd/even result
$row_oddEven_result = null;
//check if the current row is odd or even
if ($row_oddEven % 2 == 0) {
// if its divisible by two, it must be even
$row_oddEven_result = "even";
} else {
// othewrwise it must be odd
$row_oddEven_result = "odd";
}
?>
<div class="row-is-<?= $row_oddEven_result; ?>">
This row is <?= $row_oddEven_result; ?>!
</div>
<?php
} // endforeach loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment