3

I am attempting to display entries from a specific channel 7 days before and 7 days after an entry_date from another entry. I don't want to use a plugin because.

Here's how I am getting / calculating the 7 days prior / 7 days after:

{exp:channel:entries channel="pd_request_form" entry_id="{segment_2}"} <?php $php_7_days_before = date ("Y-m-d H:i", floor('{entry_date}' - 604800)); ?>{/exp:channel:entries}
{exp:channel:entries channel="pd_request_form" entry_id="{segment_2}"} <?php $php_7_days_after = date ("Y-m-d H:i", floor('{entry_date}' + 604800)); ?>{/exp:channel:entries}

Here's what works:

{exp:channel:entries channel="pd_request_form" dynamic="no" start_on="2013-01-10 00:00" stop_before="2013-01-24 00:00"}

    {title} - {entry_date}<br />

{/exp:channel:entries}

The dynamic="no" is there because the URL has an entry_id in it. I see entries I would expect to see.

Here's what also works:

<?php echo $php_7_days_before; ?>
<?php echo $php_7_days_after; ?>

When I say it works I mean, it produces output that looks correct to me.

But here is what isn't working:

{exp:channel:entries channel="pd_request_form" dynamic="no" start_on="<?php echo $php_7_days_before; ?>" stop_before="<?php echo $php_7_days_after; ?>"}

    {title} - {entry_date}<br />

{/exp:channel:entries}

I think I'm missing something simple, but I'm not seeing it.

2

Your issue here is one of parse order. Changing to php on input won't help. Leave it on output.

I just tested this:

{exp:channel:entries channel="blog" limit="1"}
 <?php $php_7_days_before = date ("Y-m-d H:i", floor('{entry_date}' - 604800)); ?>
 {/exp:channel:entries}
 {embed="site/php_test" 7daysbefore="<?php echo $php_7_days_before; ?>" }

Then in your embedded template you can call start_on="{embed:7daysbefore}"

| improve this answer | |
2

Set PHP Parsing Stage to 'Input' in your template file.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.