Hello,
Is it possible to start a set of channel entries then stop to display ads and then start another set of channel entries starting again from where the initial channel entries left off?
Here’s the code I’m running now:
{exp:channel:entries channel="news" orderby="entry_date" sort="desc" limit="2"}
<div>Entry Info</div>
{/exp:channel:entries}
{snp_right_ad_column_mobile} <!-- Ads that are being display through a different channel entry-->
{exp:channel:entries channel="news" orderby="entry_date" sort="desc" limit="6" dynamic="no" offset="2"}
<div>Entry Info</div>
{/exp:channel:entries}
The problem I’m running into now is on the subsequent pages, the first two entries are the same as on the first page. the entries below the ads are in correct order.
The other solution I thought of was to use a modulus operator like this:
{exp:channel:entries channel="news" orderby="entry_date" sort="desc" limit="8"}
{if count % 5 == 0}
{snp_right_ad_column_mobile}
{/if}
<div>Entry Info</div>
{/exp:channel:entries}
But I get the following error: Something has gone wrong and this URL cannot be processed at this time.
From what I understand you cant call another loop within another loop.
Let me know you have any suggestions.
Thanks!
Without seeing what code is in your snippet I’m guessing that may be tripping things up - does your entries tag work without the snippet (in your 2nd example)?
What I’d do is use an embed template to pull in the ad entry, that way you can pass data like category ID so you can filter what ad(s) may get displayed from your ads channel.
Thanks Rob, in the 2nd example it works without a snippet.
Here’s the code inside of that snippet:
<div class="adColumnMobile">
{exp:channel:entries channel="ads" limit="4" category="110" orderby="ads_order" sort="asc"" dynamic="no"}
<a href="http://{ads_url}"> {ads_image}</a>
{/exp:channel:entries}
</div>
I’d suggest putting the ad code in an embed template.
The embed template:
<div class="adColumnMobile">
{exp:channel:entries channel="ads" limit="4" category="110" orderby="ads_order" sort="asc"" dynamic="no"}
<a href="http://{ads_url}"> {ads_image}</a>
{/exp:channel:entries}
</div>
Your news template
{exp:channel:entries channel="news" orderby="entry_date" sort="desc" limit="8"}
{if count % 5 == 0}
{embed="your-template-group/your-ad-template"}
{/if}
<div>Entry Info</div>
{/exp:channel:entries}
Yes you could use a conditional tag in your entries tag, something like this:
{exp:channel:entries channel="news" orderby="entry_date" sort="desc" limit="8"}
{!-- embed the ad at the 4th entry --}
{if count == 4}
{embed="your-template-group/your-ad-template"}
{/if}
<div>Entry Info</div>
{/exp:channel:entries}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.