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.

Show entry from different weblog at set intervals

April 20, 2009 12:53pm

Subscribe [1]
  • #1 / Apr 20, 2009 12:53pm

    Casey Reid

    82 posts

    I have an event weblog and a sponsors weblog. What I’d like to do is show a sponsor from that weblog after every 3rd event from the event weblog. I also need it to show the next sponsor in line. Here’s the idea:

    Event Listing 1
    Event Listing 2
    Event Listing 3
            - Sponsor 1

    Event Listing 4
    Event Listing 5
    Event Listing 6
            - Sponsor 2

    etc.

    This is probably made more complicated by the fact that I’m using the Repeet plugin for event display so I’ll probably need to use an embed to pull in the sponsors.

    I’m thinking I’ll need to maybe use PHP for a counter combined with the backspace parameter to only show the sponsor embed every 3 listings and backspace it by the counter as well?

    Any suggestions?

  • #2 / Apr 20, 2009 1:21pm

    ender

    1644 posts

    my initial reaction would be to loop through your weblog entries as usual, except instead of outputting html directly, insert the data into a php array.  then do the same thing for your sponsor information into another php array.  then after the weblog entries loops are done use a php loop through the first array printing entries and when (counter % 3 == 2) pop the next sponsor off the array and print it out (% is the modulus operator, basically the remainder if you were doing long division by hand).

    there may be a better way or one with less php but this should give you absolute control over what shows up where.

  • #3 / Apr 20, 2009 2:18pm

    Casey Reid

    82 posts

    Thanks @ender. That helped with part of my solution. It looks like this will work for me (simplified).

    <?php
    $counter=1;
    $offsetter=0;
    ?>
    
    {exp:weblog:entries weblog="events"}
    <?php
    if (($counter % 3) == 2){
    ?>
        {embed="_includes/sponsors" offsetter="<?php echo $offsetter?>"}
    <?php
        $offsetter++;
    }
    
    $counter++;
    ?>
    {/exp:weblog:entries}

    Then in the sponsors embed:

    {exp:weblog:entries weblog="sponsors" dynamic="off" limit="1" offset="{embed:offsetter}"}
                {sponsor_homepage_image}
    {/exp:weblog:entries}

    Basically I’m just showing the sponsor every 3 listings and increasing the offset by 1 each time to move up the list of sponsors. Just need to adjust the counter, offsetter, and modulas operator for specific control over over when to display the sponsors.

  • #4 / Apr 20, 2009 3:00pm

    ender

    1644 posts

    the one “gotcha” I could potentially see with doing it that way is that you’re hitting your database with more queries than necessary with that embed (unless you’re caching aggressively).  It would only be an issue if your server came under some pretty serious load though, so it may be of no consequence.

  • #5 / Apr 20, 2009 3:45pm

    Casey Reid

    82 posts

    Agreed. That’s definitely something I thought about. I’ll be doing some basic caching, but I don’t think this particular site will be under a serious load. I may rework this to account for that possibility though. Thanks for the heads up.

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

ExpressionEngine News!

#eecms, #events, #releases