EllisLab text mark
Advanced Search
     
Working with categories - this should be simple!
Posted: 13 July 2012 07:03 PM   [ Ignore ]
Avatar
Joined: 2011-06-29
44 posts

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>
      <
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} &nbsp;{business_zip_code}
        
</p>
                
      
{/exp:channel:entries}

    {
/if} 

 

 
Posted: 14 July 2012 01:51 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2003-01-07
693 posts

Remember EE pagination in your plan (we use the word “page” in our projects), and think about the URI from right to left in your conditionals and simplify conditionals to allow the use of simple conditionals whenever possible.

{if segment_3 AND segment_3 != 'page'}
  Single Entry
 {
/if}
 {if segment_2 
AND (segment_3 == '' OR segment_3 == 'page')}
  Multi Entry
 {
/if}
 {if segment_1 
AND segment_2 == ''}
  Multi Entry
 {
/if}
 {if segment_1 
== ''}
  Home
 {
/if} 

When we’re trying to single out /uri_segments/ thinking from right to left gives us more consistent results.

 Signature 

learn more at eeSiteKit.com


NetRaising | a web services company


Custom Designed Dynamic Websites for Mission Driven Organizations

 
Posted: 17 July 2012 11:04 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2011-11-25
7174 posts

Hey adb7901,

Thank you for posting your question here on the ExpressionEngine forums.

Does what Kurt said make sense? Can you go through your code and organize it a bit better?

Thank you,

 Signature 

Recent version: EE 2.5.4 | Forum Module 3.1.10 | MSM 2.1.4 | 2.x Bug Tracker | Version Upgrade