I’m creating a business directory. I’m using one page to display categories, then one category with the businesses in that category, then one business, and I’m trying to use segment variables to pass along all the information I need to use to choose the right data to display.
The main point of all of this is to get search engine friendly URLs, and to be able to assign channel entries to more than one category and have them show up in each of the categories they’re assigned to.
This section works:
{if segment_2=="" AND segment_3==""}
{exp:channel:categories
channel="business_categories"
orderby="url_title"
sort="asc"
}
<h2><a href="{site_url}/directory/{category_url_title}">{category_name}</a></h2>
<p class="indent">{category_description}</p>
{/exp:channel:categories}
This section displays the category name and description, but not the entries in that category, therefore the query is working:
{if:elseif segment_2!="" AND segment_3==""}
{exp:query
sql="SELECT cat_id FROM exp_categories WHERE cat_url_title = '{segment_2}'"
}
{exp:channel:categories
channel="business_listings"
show="{cat_id}"
}
<h1>{category_name}</h1>
<p>{category_description}</p>
<h3><a href="{site_url}/directory/{category_url_title}/{url_title}">{business_name}</a></h3>
<p>
{business_street_address}<br />
{business_city}
</p>
{/exp:channel:categories}
{/exp:query}
The EE tags starting with “business” are in the business_listings channel. Since the channel category doesn’t have fields called “business_name”, I get the unrendered EE tags on output. I’ve tried putting another loop in: {exp:channel:entries channel=“business_listings” category=“cat_id”}{/exp:channel:entries}, but no joy.
The final section doesn’t work at all, but it’s supposed to show one single channel entry from “business_listings”. It seems really straightforward and I can’t imagine what’s wrong with it.
{if:elseif segment_3!=""}
{exp:channel:entries
channel="business_listings"
url_title="{segment_3}"
}
<h2>{business_name}</h2>
<p><a title="{business_name}" href="{business_web_address}" target="_blank">{business_web_address}</a></p>
<p>
{business_street_address}<br />
{business_city}, {business_state} {business_zip_code}
</p>
{/exp:channel:entries}
{/if}
