0

Ok, my site is made up of Cities and Properties within each city. The usual flow is on the homepage there is a list of Cities, you click a city and it goes through to a City view which will then have a list of Properties, to which you can click through to a Property view.

Well some of my Cities only have 1 property, so I would like the link from City to go directly to the Property view, not the city view.

{exp:channel:entries channel="city" dynamic="no" orderby="city_sort_order" sort="asc"}
                <li class="location-box colour-{city_colour}">
                    <a href="{url_title}">
                        <div class="location-box colour-{city_colour}">
                            <figure>
                                <h1>{title}</h1>
                                <img src="{city_main_image}" alt="">
                            </figure>
                        </div>
                    </a>
                </li>
                {/exp:channel:entries}

Any advice?

4
  • 1
    How are the properties saved for every city? Is it a grid? A playa? Relationships?
    – Sobral
    Feb 19 '14 at 21:38
  • 1
    In Property channel I have a field for Property City and that is Playa.
    – Nick Toye
    Feb 19 '14 at 22:10
  • So, the properties aren't childrenof cities, but the cities are children of properties? Do I get it right?
    – Sobral
    Feb 19 '14 at 23:40
  • Robson, do you want to take a look? Skype me and I'll give you access.
    – Nick Toye
    Feb 20 '14 at 0:55
1

You can count how many playa:parents the city has.

{exp:channel:entries channel="city" dynamic="no" orderby="city_sort_order" sort="asc"}
<li class="location-box colour-{city_colour}">
    <a
    {if '{exp:playa:total_parents field="property_city"}' == 1}
        {exp:playa:parents field="property_city" var_prefix="property"}href="/{url_title}/{property:url_title}"{/exp:playa:parents}
    {if:else}
        href="/{url_title}"
    {/if}
    >
        <div class="location-box colour-{city_colour}">
            <figure>
                <h1>{title}</h1>
                <img src="{city_main_image}" alt="">
            </figure>
        </div>
    </a>
</li>
{/exp:channel:entries}

Please, test this code.

1

count the number of properties. if the number of properties ==1 redirect to the property. How to code it exactly is upto the way you've set up the properties and cities channels

2
  • How do you mean how I have set them up?
    – Nick Toye
    Feb 19 '14 at 17:51
  • i meant the same as the answer by Robson Sobral Feb 20 '14 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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