I want to use the PHP counter described in this wiki article, but limit its count to only include articles passing an EE conditional test. Here is what I have that doesn’t work:
<?php $entry_count=0; ?> <!-- initialize a variable -->
{exp:weblog:entries weblog="advertisements" orderby="entry_id" sort="asc" dynamic="off" status="open"}
{if ad_active_inactive=="Active"}
<?php $entry_count++; ?> <!-- increment the variable -->
{/if}
{/exp:weblog:entries}
<?PHP
$minuteR = date("i"); // this gets the minute numeral for the following operation
$offset = ($minuteR % $entry_count); // this uses the modulo operator gives the remainder of zero through whatever changing by the minute
$totalR = $entry_count;
?>
{embed="embed_templates/_ads_rotator" theOffset="<?PHP echo ($offset); ?>" theTotal="<?PHP echo $totalR; ?>" }
I use the entry_count to parse an offset based upon the minute to rotate some scrolling sidebar ads, as described in my wiki entry called Rotate Sidebar Ads Sequentially. Before you tell me I can use status for this issue, the designer has included an “Active/Inactive” radio button field in the weblog entry form to make it easier for the author to designate the status, so that’s why I’m trying to test for the contents of that field.
Problem is, it parses the PHP counter before the if/then statement, so I get the same number every time (all the entries) instead of a count of the smaller number of entries that have that particular field set to “Active”.
Any ideas? I need the PHP to parse on output, I believe, for this to work, if that makes any difference. But I could be all wrong about that.
Terry Leigh Britton
