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.

Clean URLs with categories: more than 3 segments

February 27, 2012 4:29pm

Subscribe [4]
  • #1 / Feb 27, 2012 4:29pm

    e.b.

    31 posts

    Hello,

    I’ve used this code posted at http://fortysevenmedia.com/tuts/ee_cat_url.txt as a basis for one of my channels:

    <!--The Categories Page ///////////////////////////////////////////////////////////////-->
    
    {if segment_2=="" AND segment_3==""}
     
    
    {exp:weblog:categories weblog="yours" style="linear"}
    
     <a href="http://{path=">{category_name}</a>
     
    {/exp:weblog:categories}
     
    
    <!--The Category Entries Page ///////////////////////////////////////////////////////////////-->
    
    {if:elseif segment_2!="" AND segment_3==""}
    
    {exp:query sql="SELECT cat_id FROM exp_categories WHERE cat_url_title = '{segment_2}'"}
    
     {exp:weblog:entries weblog="yours" category="{cat_id}"} 
     
         <a href="http://{title_permalink={segment_1}/{segment_2}}">{title}</a>
         
     {/exp:weblog:entries}
     
    {/exp:query} 
     
    
    <!--The Single Entry ///////////////////////////////////////////////////////////////-->
    
    {if:elseif segment_3!=""}
    
    
    {exp:weblog:entries weblog="yours" limit="1" url_title="{segment_3}"}
    
    Call whatever custom fields you have here
      
    {/exp:weblog:entries}
    
     
    {/if}


    The problem I’ve come across is that I’d like to extend the functionality to segment_4 but can’t accomplish this nomatter what I try.
    My structure is the following:

    <!--The Category Entries Page ///////////////////////////////////////////////////////////////-->
    {if segment_2!="" AND segment_3==""}
    
    showing my entries per category:
    <a href="http://www.mysite.com/channel/category/">http://www.mysite.com/channel/category/</a>
    FINE
    
    <!--The Category Entries Page PER YEAR ///////////////////////////////////////////////////////////////-->
    {if:elseif segment_3!=""}
    
    showing my entries per category AND filtered by year:
    <a href="http://www.mysite.com/channel/category/year">http://www.mysite.com/channel/category/year</a>
    FINE
    
    <!--The Single Entry ///////////////////////////////////////////////////////////////-->
    {if:elseif segment_3!=""}
    
    required to show the single entry:
    <a href="http://www.mysite.com/channel/category/year/url_title">http://www.mysite.com/channel/category/year/url_title</a> or
    <a href="http://www.mysite.com/channel/category/url_title">http://www.mysite.com/channel/category/url_title</a>
    PROBLEM

    I’ve tried to shift the entry to segment_4 but it doesn’t work.
    So far I’ve been spending 3 days on solving this problem and am quite discouraged. Any help would be highly apreciated!

    Kind regards,

    E.

     

  • #2 / Feb 27, 2012 5:03pm

    glenndavisgroup

    436 posts

    Hi E,

    Try replacing your:

    {if:elseif segment_3!=""}

    with:

    {if:elseif segment_3!="" AND segment_4==""}
    
    ...your code here
    
    {if:elseif segment_4!=""}
    
    ...your code here
    
    {/if}

    Mike

  • #3 / Feb 27, 2012 6:44pm

    ChiefAlchemist

    913 posts

    Glenn might be correct.

    None the less I’ll add that you might also consider setting dynamic=“no”. Even now and then I’ve run into funk keyword type conflicts. It’s been a while so I can’t give you real example. But it was something like a channel row and a category had the same URL, or something similar.

    The point is, when dynamic=“yes” EE is making some assumptions and doing what is “standard” based on the URL it just parsed. If it assumes wrong then you could get unanticipated results. When you set dynamic=“no” you’re basically tell EE not to assume and that you’ll dictate the nature of the query.

  • #4 / Feb 27, 2012 7:48pm

    Enviromed

    375 posts

    You might consider rethinking this to use laisvunas subsegment addon on devot-ee.

  • #5 / Feb 27, 2012 9:13pm

    ChiefAlchemist

    913 posts

    Linky?

    But more importantly, why go this other route?

  • #6 / Feb 27, 2012 9:29pm

    Enviromed

    375 posts

    It’s so simple. How much is three days of your life worth?

  • #7 / Feb 27, 2012 10:37pm

    ChiefAlchemist

    913 posts

    What’s so simple? The link you posted? Your insights on the tool you mentioned? What is this, an Easter egg hunt?

  • #8 / Feb 28, 2012 4:00pm

    e.b.

    31 posts

    Hi E,

    Try replacing your:

    {if:elseif segment_3!=""}

    with:

    {if:elseif segment_3!="" AND segment_4==""}
    
    ...your code here
    
    {if:elseif segment_4!=""}
    
    ...your code here
    
    
    
    
    {/if}

    Mike

    Hello Mike,

    Thank you for your reply!
    I’ve already tried this … doesn’t work. In fact, I’ve already tried everything I could think of of being crucial … Any other suggestion?

  • #9 / Feb 28, 2012 4:03pm

    e.b.

    31 posts

    Glenn might be correct.

    None the less I’ll add that you might also consider setting dynamic=“no”. Even now and then I’ve run into funk keyword type conflicts. It’s been a while so I can’t give you real example. But it was something like a channel row and a category had the same URL, or something similar.

    The point is, when dynamic=“yes” EE is making some assumptions and doing what is “standard” based on the URL it just parsed. If it assumes wrong then you could get unanticipated results. When you set dynamic=“no” you’re basically tell EE not to assume and that you’ll dictate the nature of the query.


    Hello Chiefalchemist,

    I will have a try with dynamic=“no” before I consider using an add-on. Result will be posted 😉

    Thanks,

    E.

  • #10 / Mar 01, 2012 3:27pm

    e.b.

    31 posts

    Hello everybody,

    I had a try with dynamic=“no” and I got no result, which means that the url is properly constructed but the full entry isn’t shown.
    Here is my shortened code for a better understanding:

    1. The category entries listed per year

    <!--The Category Entries Page PER YEAR ///////////////////////////////////////////////////////////////-->
          {if:elseif segment_3!=""}
                {exp:gwcode_catmenu channel="aktuelles" cat_url_title="{segment_2}" style="simple" excl_cat_id="15"}
                   <a href="http://{path=%27aktuelles/{cat_url_title}%27}" class="cur">{cat_name}</a>
                {/exp:gwcode_catmenu}
                
                <div class="content_text">
                 {exp:yearlist channel="aktuelles" category="13"}
                  <a href="http://{path=%27{segment_1}/{segment_2}/{year}%27}" class="year">{year}</a>
                 {/exp:yearlist}
                         
                 <ul class="article_listing">
                  {exp:query sql="SELECT cat_id FROM exp_categories WHERE cat_url_title = '{segment_2}'"}      
                  {exp:channel:entries channel="aktuelles" limit="10" paginate="bottom" orderby="date" sort="desc" disable="member_data" category="{cat_id}" year="{segment_3}"}
                   <li class="click"> 
                    <h5><span class="date">{entry_date format="%d.%m.%Y"}</span> <a href="http://{title_permalink={segment_1}/{segment_2}}">{title}</a></h5>
    <p>                {aktuelles_subtitle}<br />
                   </li><br />
                  {/exp:channel:entries}<br />
                 </ul><br />
                </div><br />
          {/if}

    2. The single entry
    at http://www.mysite.com/channel/category/year/url_title
    or http://www.mysite.com/channel/category/url_title

    <!--The Single Entry ///////////////////////////////////////////////////////////////-->
          {if:elseif segment_4!=""}
    
                {exp:gwcode_catmenu channel="aktuelles" cat_url_title="{segment_2}" style="simple" excl_cat_id="15" category="13"}
                   <a href="http://{path=%27aktuelles/{cat_url_title}%27}" class="cur">{cat_name}</a>
                {/exp:gwcode_catmenu}
      
                <div class="content_text">
                 {exp:channel:entries channel="aktuelles" limit="1" url_title="{segment_4}" dynamic="no"}
                  <h2>{title}</h2>
    <p>              {aktuelles_body}<br />
                 {/exp:channel:entries} <br />
                </div></p>
    
    <p>      {/if}

    Adding a segment_3 to

    <a href="http://{title_permalink={segment_1}/{segment_2}}">{title}</a>

    hasn’t brought me further either.
    Any other suggestions?

    Kind regards,

    E.

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

ExpressionEngine News!

#eecms, #events, #releases