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.

URL Parsing Incorrectly

December 04, 2012 3:26pm

Subscribe [1]
  • #1 / Dec 04, 2012 3:26pm

    Aerdan

    2 posts

    Hello,

    I’m trying to figure out why my URL isn’t working the way that it is supposed to. For this particular template, the structure is as such:

    http://www.example.com/latest/{category}/{url_title}

    So latest is segment_1, the category is segment 2, and the url_title from the post is segment_3. At the beginning of the code I’m parsing the URL, but I’m not getting the results that I would expect. Even with multiple segments, I hit the “404” error from the results right away. Here is the code:

    {!-- Break Apart URL for Page Processing --}
    {if segment_3!=""}
    
     {!-- Segment 3 Exists: Check URL for Validity --}
     {exp:channel:entries
      channel="latest"
      url_title=segment_3
      disable="categories|category_fields|custom_fields|member_data|pagination"
      limit="1"}
    
      {if no_results}
       {!-- Entry Not Found: 404 --}
      {if:else}
       {!-- Entry Found: Display Single Post --}
      {/if}
     {/exp:channel:entries}
    
    {if:else}
    
     {!-- Segment 3 Does Not Exist: Begin Segment 2 Breakdown --}
     {if segment_2!=""}
    
      {if segment_2=="history"}
       {!-- Segment 2 is History: Display Full Post History --}
      {if:else}
       {!-- Top Level is at Category Level (2): Verifying Category Exists --}
       {exp:query
        sql="SELECT cat_id, cat_name
        FROM exp_categories
        WHERE cat_url_title = '{segment_2}'
        LIMIT 1"}
        {if no_results}
         {!-- Category Does Not Exist: Redirect to Home --}
        {if:else}
         {!-- Category Exists: Displaying Category Feed --}
        {/if}
       {/exp:query}
      {/if}
     {if:else}
      {!-- No Segment 2 or 3: Display All Content --}
     {/if}
    {/if}

    Let me know if I can provide anything else that can illuminate the issue. Thanks in advance!

  • #2 / Dec 05, 2012 9:32am

    MadWebDesigns

    147 posts

    Hi Andy,

    I think you have a typo in the first channel entries tag. Try changing it to the following:

    ...
    {!-- Segment 3 Exists: Check URL for Validity --}
     {exp:channel:entries
      channel="latest"
      url_title="{segment_3}"
      disable="categories|category_fields|custom_fields|member_data|pagination"
      limit="1"}
    
      {if no_results}
       {!-- Entry Not Found: 404 --}
      {if:else}
       {!-- Entry Found: Display Single Post --}
      {/if}
     {/exp:channel:entries}
    ....

    The url_title parameter needs to be url_title=”{segment_3}”. I hope that helps.

    Cheers,

    Mike

  • #3 / Dec 05, 2012 4:45pm

    Aerdan

    2 posts

    Hey everyone,

    I found the solution and it wasn’t what I expected. When I checked out Low’s post on snippets and variables, the issue became apparent:

    http://gotolow.com/blog/snippets-and-preload-replace-variables

    I figured the nested code in this wasn’t important to post, but in fact, it was. To help optimize the code later in the page, each section has its own preload_replace attached to it. As it turns out, preload_replace will only accept one instance of a declaration. This can be changed by using {if} statements, however, the conditionals have to be simple. Since I have {if}{else}, it will parse too late and it is defaulting ot using the first instance of my preload_replace.

    Restructuring my content into simple statements solves the problem. I hope this helps someone in the future!

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

ExpressionEngine News!

#eecms, #events, #releases