0

I'm working on a site which has a series of tours, some of which are related (using playa) for when a tour is available on alternateive dates.

The problem I have is I want to display a list of all the tours, but instead of showing the title, link and date for all of them. If a tour has an alternative date/relationship it displays the title once with the alternative dates listed underneath. So it outputs like this:

Tour title 1
- Date a (links to Tour title 1 page)

Tour title 2
- Date b (links to Tour title 2 page)
- Date c (links to Tour title 3 page)
- Date d (links to Tour title 4 page)

Tour title 5
- Date e (links to Tour title 5 page)
- Date f (links to Tour title 6 page)

Tour title 7 (links to Tour title 7 page)
- Date g (links to Tour title 8 page)

If any one could offer any advice I'd appreciate it. Thanks.

To give a bit more information about the configuration of the channels:

I have a channel for each Tour entry called 'tour', that has all the information about the tour, including date, price etc. There are some tours which might run several times a year, but may have different costs, flights etc, (which is why each has to be an entry in it's own right.) Within the 'tour' channel I have a Playa field {alternative_tour_dates} which lists all the tours. This would be used to 'link' the tours with alternative dates to each other.

This is my template which I want to show all the tours, but with the tours that have multiple dates, rather than displaying each one, it displays the tour that has the earliest date and lists the alternative dates, cost and url of the others.

{exp:channel:entries channel='tour' disable="category_fields|member_data" show_future_entries="yes" orderby="tour_date_start" sort="asc" search:tour_type="tour"}
                    <div class="unit3">
                        <div class="unit1 unitpadding grey overview">
                            <a href="{url_title_path='tours/'}"><h3>{tour_name}</h3></a>
                            <h4>Tour Director: {tour_to_tour_personnel}<a href="{site_url}tour-directors/{url_title}">{tour_director_name_first} {tour_director_name_last}<br /></a>{/tour_to_tour_personnel}</h4>
                            <ul>
                                <li><a href="{site_url}tours/{url_title}">{tour_date_start format="%j %F"} &ndash; {tour_date_end format="%j %F %Y"}</a> <span class="price">&pound;{tour_base_price}</span></li>
                                <li>{alternative_tour_dates}<a href="{site_url}tours/{url_title}">{tour_date_start format="%j %F"} &ndash; {tour_date_end format="%j %F %Y"}</a> <span class="price">&pound;{tour_base_price}</span>{/alternative_tour_dates}</li>
                            </ul>
                        </div>
                    </div>
{/exp:channel:entries}

Once again thanks for input so far.

1
  • I would love to help out but i am needing a bit more information about how your data is structured. Would you mind adding some more information about how your data is set up? Commented Jul 6, 2014 at 16:17

2 Answers 2

1
+50

I am going to give you a solution that would work not knowing how your channel entries are set up if i had more information i know i could figure this out for you with playa, however this solution will work just fine.

IF Tour titles and Dates are a one to many relationship meaning you are having for each Tour title 1 or more dates associated to it. You could accomplish it this way.

Create a tour title category group and create categories for each tour title. We'll say for the example it is category group 1.

Create a channel thats your tour date and information, and associate each one to a category in the group.

Now for code.

Create a separate template with your code in it for the tour dates.

File path: temlates/default_site/yourtemplate.group/_dates.html

<h1>{embed:tour_title}</h1>
{exp:channel:entries channel="tour_dates" category="{embed:cat_id}"}
   {!-- Your tour dates data --}
{/exp:channel:entries}

Then embed that template from your tour title template passing data into the two variables specified above "tour_title" and "cat_id".

{exp:channel:categories category_group="cat_id_of_tour_group"}
   {!-- now we are going to loop through every category that has data assoiated with it in your system and pass the specific cat id and title through to the other template we created to generate the specific data needed. --}
   {embed="yourtemplate/_dates" cat_id="{category_id}" tour_title="{category_name}"}
{/exp:channel:categories}

Like I said this isn't a solution using playa, but because of your limited information i had to come up with a more standard native EE solution.

2
  • Thanks Matt, I really appreciate your advice and initially tried this and it works in principle. The problem I have is that there are potentially 100's of tours, (this data is being pushed in from the clients internal database) So creating a category for each one isn't going to work for them. It would be great if there is a solution using Playa? I'll edit my original question with more details if you are able to advise? thanks
    – Erbert
    Commented Jul 18, 2014 at 12:08
  • Yes I'll keep a look out! Commented Jul 18, 2014 at 12:34
2

Assuming that the alternate dates are related to the "parent" tour via a Playa field in each "alternate" entry (so the alternate dates are "children"), you'd simply do this:

{exp:channel:entries channel="tours"}
    <h3>{title}</h3>
    <ul>
        <li><a href="{title_permalink="tours/view"}">{tour_date}</a></li>
        {exp:playa:children channel="tours" field="parent_tour"}
        <li><a href="{title_permalink="tours/view"}">{tour_date}</a></li>
        {/exp:playa:children}
    </ul>
{/exp:channel:entries}

(Your channel and field names will differ obviously.)

2
  • Thanks for the quick reply Derek. I can see what you have done there and it nearly works, but the problem I have is that each entry is related to each other via a Playa field, so each entry is in fact a parent and a child. I need this to work like this because if I just made the 1st tour the parent and then made the others children of it, when the date expires on the 1st tour the children would then not display. Ideally ee would always show the next tour based on the upcoming date and then have any other dates as children??
    – Erbert
    Commented Jul 3, 2014 at 22:46
  • Maybe you should set it up a bit different then. One channel with the tour info and description, another (related) channel with the dates. Another approach is to give each tour a specific (internal) tour_id field to group by.
    – GDmac
    Commented Jul 8, 2014 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.