Created
December 1, 2020 13:50
-
-
Save FreshLondon/be700f64700030fb61c1febf91b49fff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// 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