ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Custom sidebar ad to replace random sidebar ad on per-entry basis

March 28, 2011 7:12pm

Subscribe [2]
  • #1 / Mar 28, 2011 7:12pm

    ChrisClark

    60 posts

    Hello, all.

    I’m running EE 2.1.3 and here’s what I’m trying to do:

    I have a Channel for ads that is powering a random sidebar ad on my site geekforcefive.com. I would like to be able to replace this random sidebar ad with a custom ad on the single entry page of some entries in my main channel. What is the best way to do this? Related entries? A series of if statements? Please let me know what you think.

    Thanks so much,
    Chris

  • #2 / Mar 28, 2011 7:44pm

    Boyink!

    5011 posts

    One specific ad for one specific entry?  Relationship.

  • #3 / Mar 28, 2011 7:59pm

    ChrisClark

    60 posts

    Yes, that’s what I was planning. And that makes sense.

    The issue I can’t wrap my head around is how to make the ad random when I _don’t_ specify an ad for the specific entry. I see that there’s a {if no_related_entries} conditional, but could I throw a Channel tag pair for the Ad channel into that conditional without significantly degrading performance? Or is there some other way I would handle this?

  • #4 / Mar 28, 2011 8:04pm

    Boyink!

    5011 posts

    You can look to see that there is a value in the relationship field by checking to see if it has a “0”:

    {if relationship_field != "0"}
      relationship loop
    {/if}
    
    {if relationship_field =="0"}
    channel entries / random loop
    {/if}
  • #5 / Mar 28, 2011 9:20pm

    ChrisClark

    60 posts

    Okay. That makes sense to me. Now, is it going to be okay to nest that ad channel entries/random loop within the main channel entries loop? It would look like this, right?

    {main channel entries loop}
    {if relationship_field != "0"}
      relationship loop
    {/if}
    
    {if relationship_field =="0"}
    ad channel entries / random loop
    {/if} 
    {/main channel entries loop}

    In perusing some other threads, it seemed to me that nesting channel loops could be a very bad thing. Any tips on how to avoid it being bad?

  • #6 / Mar 28, 2011 9:25pm

    Boyink!

    5011 posts

    That’s the part you currently have working now, no?  If not, you may want to put it in an embedded template, but it sounds like this would be a single-entry loop nested in a single-entry loop which I wouldn’t worry about.  I’ve nested far more complex entries/loops with no discernible performance issues.

  • #7 / Mar 28, 2011 9:36pm

    ChrisClark

    60 posts

    Yep, that’s the part I have working now, though it’s not yet nested within another loop. Glad to know that a single-entry loop inside a single-entry loop isn’t cause for worry. Thanks for the help!

  • #8 / Mar 28, 2011 9:39pm

    Boyink!

    5011 posts

    OK - just be aware that you may have to place the nested loop into an embedded template to avoid conflicts between the two loops.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases