We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Splitting entries to place Ads

How Do I?

Red's avatar
Red
3 posts
about 5 years ago
Red's avatar Red

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!

       
Rob Allen's avatar
Rob Allen
2,950 posts
about 5 years ago
Rob Allen's avatar Rob Allen

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.

       
Red's avatar
Red
3 posts
about 5 years ago
Red's avatar Red

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>
       
Rob Allen's avatar
Rob Allen
2,950 posts
about 5 years ago
Rob Allen's avatar Rob Allen

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}
       
Red's avatar
Red
3 posts
about 5 years ago
Red's avatar Red

Awesome, that worked! Now if I wanted to splice inside an entry between half of the paragraphs displayed could that be done natively?

       
Rob Allen's avatar
Rob Allen
2,950 posts
about 5 years ago
Rob Allen's avatar Rob Allen

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}
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.