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.

How to Display Ad that matches Category of Entry/article

March 28, 2011 4:59am

Subscribe [2]
  • #1 / Mar 28, 2011 4:59am

    vicos

    22 posts

    This is a little confusing, so please bear with me.

    SUMMARY: Want to display text ads whose category matches the category of the entry/article upon which it is displayed.

    DETAILS: I have two/2 channels: blog and sponsors. They both share the same category group.

    Sponsors is a simple channel with title, URL, and teaser/text.

    Basically, if the reader is displaying a page of articles belonging to CATEGORY 12 ( test.com/category/12), then display a RANDOM sponsor entry which has also has an assigned category of 12.

    If the reader is viewing a single article, display a sponsor which has a category that matches one of the articles categories— keeping in mind that both blog entries and sponsor enries can have many categories assigned.

    Finally, if there are no matching records, then display any random sponsor, i.e. we have to display something.

    So far, I have a random_sponsor template that basically pulls a random entry with no consideration of category:

    <div class="widget widget_text">
    <h3>Featured Sponsor</h3>
    <p><div class="textwidget"></p>
    
    <p>{exp:channel:entries channel='sponsors' limit='1' dynamic='no' orderby='random' disable='member_data|pagination'}<br />
    <b>{title}</b><br />
    {sponsor_url}<br />
    {sponsor_teaser}<br />
    {/exp:channel:entries}</p>
    
    <p><br />
    </div><br />
    </div>


    Can it be done?

  • #2 / Mar 28, 2011 1:14pm

    Sue Crocker

    26054 posts

    Hi, vicos.

    See: http://ellislab.com/expressionengine/user-guide/modules/channel/conditional_variables.html#cond_if_category_request

    You’d use this bit of code if it was on a category page.

    You’d also need to loop through the categories loop, would it make sense to pick a count of one?

    This is more of a How Do I kind of question, so it may get moved over to the CodeShare Corner.

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

ExpressionEngine News!

#eecms, #events, #releases