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.

Category URL system (Almost working!)

September 25, 2012 4:16pm

Subscribe [2]
  • #1 / Sep 25, 2012 4:16pm

    dhjones

    25 posts

    Excuse the markup, its going to change - its using YUI3 grids.

    What follows is my page markup, it almost works except for two things marked by **HELP**.

    I am using Low seg2cat

    {embed="embeds/html_header"}
    <body>
      <div id="container"> 
        <div id="wrap">
          <!-- hd -->
          {embed="embeds/header"}
          <!--//hd -->
          
      
          <div class="clearfix">
            <!-- bd -->    
            <div id="bd">
              <div class="yui3-g">
                
                <div class="yui3-u" id="side">
                  <div id="menu">
                    <ul id="treeMenu" class="menu">
                      {exp:channel:categories}
                      <li>**HELP**
                        <a href="/recipes/{category_url_title}">_                      {category_name}        _                    </a>               
                      </li>
                      {/exp:channel:categories}                     
                    </ul>
                  </div><!--//#menu -->         
                </div><!--// #side --> 
                
                <div class="yui3-u" id="main">
    
                    {if segment_2 == ""}
                      <div class="w">
                        <h1>Latest Recipes</h1>
                      </div>
                      <div class="w">
                        {exp:channel:entries channel="recipes" status="open" orderby="title" sort="asc" limit="10"}
                          <div class="yui-b article">
                              <div class="yui3-g">
                                  <div class="yui3-u-1-5">
                                      Image
                                  </div>
                                  <div class="yui3-u-4-5">**HELP**
                                      <a href="/recipes/{category_url_title}/{url_title}">{title}</a>
                                      {short_introduction}
                                  </div>
                              </div>
                          </div>  
                        {/exp:channel:entries}
                      </div>
                    {/if}
                    
                    {if segment_2 != "" AND segment_3 == ""}
                      <div class="w">
                        <h1>{segment_2_category_name} Recipes</h1>
                        {segment_2_category_description}
                      </div>
                      <div class="w">
                        {exp:channel:entries channel="recipes" category="{segment_2_category_id}" orderby="title" sort="asc" limit="10"}
                          <div class="yui-b article">
                              <div class="yui3-g">
                                  <div class="yui3-u-1-5">
                                      Image
                                  </div>
                                  <div class="yui3-u-4-5">
                                      <a href="/recipes/{segment_2_category_name}/{url_title}">{title}</a>
                                      {short_introduction}
                                  </div>
                              </div>
                          </div>  
                        {/exp:channel:entries}
                      </div>
                    {/if}
                    
                    {if segment_3 != ""}
                      <div class="w">** HELP **
                      {exp:channel:entries channel="recipes" limit="1"}
                          <h1>{title}</h1>
                          By {author}
                          {short_introduction}
                          {fact}
                      {/exp:channel:entries}
                      </div><!--// .w -->
                    {/if}
                  
                </div><!--// yui3-u --> 
              </div><!--// yui3-g -->
            </div><!--// bd -->    
          </div><!--// clearfix -->
    
        </div><!--// wrap -->       
      </div><!--// container -->
    
      <div id="ft">
          <div class="page">
              {embed="embeds/footer"}
          </div>
      </div>   
      
      {google_analytics}
      </body>
    </html>

    The three errors I need help with are:

    In order:

    1. {category_url_title} doesn’t seem to be parsed? it shows as {category_url_title} in the URL

    2. I want to use the category url not the name, as although for now these are the same (Case is different though), going forward thats going to be a problem I imagine. I need something like {segment_2_category_url}

    3. I have segments 2 and 3… so I am at /recipes/british/toad-in-the-hole

    I now want to load the recipe which has the url_title of “toad-in-the-hole” - how can I do that?

    —-

    To see what I am emulating, please take a look at:


    http://www.kitchengeekery.com/recipes/
    http://www.kitchengeekery.com/recipes/british/
    http://www.kitchengeekery.com/recipes/british/toad-in-the-hole-a123

  • #2 / Sep 25, 2012 8:33pm

    dhjones

    25 posts

    Updated with code.

  • #3 / Sep 25, 2012 9:39pm

    the3mus1can

    426 posts

    Try this:

    {exp:channel:categories channel="recipes" style="linear"}
     <li>
     <a href="/recipes/{category_url_title}">_   {category_name}        _ </a>               
     </li>
    {/exp:channel:categories}

    And:

    {exp:channel:entries channel="recipes" status="open" orderby="title" sort="asc" limit="10"}
      <div class="yui-b article">
          <div class="yui3-g">
              <div class="yui3-u-1-5">
                  Image
              </div>
              <div class="yui3-u-4-5">
               {categories limit="1"}
                  <a href="/recipes/{category_url_title}/{url_title}">{title}</a>
                {/categories}
                  {short_introduction}
              </div>
          </div>
      </div>  
    {/exp:channel:entries}

    This last one might a little tricking to get working properly depending on how many categories and how many category groups are being used. Take a look at this for more params that you can use with the categories tag pair.

  • #4 / Sep 26, 2012 6:24am

    dhjones

    25 posts

    Hello,

    Thanks for the response, and I will clarify the third point a little more.

    This structure is what it should use

    {channel}/{category}/{url_title}

    I just want to load the specific piece of content that is referenced in segment 3, at the moment, my solution only loads the first piece of content from the recipes channel, it doesn’t pay any attention to whats in segment_3.

    What is the syntax to load a piece of content, surely you can pass the {url_title} of the content into that?

    Pseudo code

    if (segment_3 != “”)
    {
    load_content_with_url( {url_title} );
    }

    Hope that helps?

  • #5 / Sep 26, 2012 12:07pm

    the3mus1can

    426 posts

    This should work:

    {exp:channel:entries channel="recipes" url_title="{segment_3}" limit="1"}
        <h1>{title}</h1>
        By {author}
        {short_introduction}
        {fact}
    {/exp:channel:entries}
  • #6 / Sep 26, 2012 7:59pm

    dhjones

    25 posts

    Hi,

    Firstly I would like to say a massive thank you for the help on this topic, it is very much appreciated.

    I now have a recipe content type which is going to allow me to add new recipes faster than ever!

    All of the changes you suggested worked without exception.

    How would I go about letting the /recipes/ and /recipes/category/ paginate? Would that not horribly confuse my segment logic, as segment_2 or segment_3 could be a number of pagination?

    What would be the most elegant way to paginate this, say in 20 per page?

    Many thanks, and I cannot wait to show the community the final result of this site!

  • #7 / Sep 26, 2012 8:03pm

    dhjones

    25 posts

    Also, any idea why a CSS file when edited directly doesn’t show the changes, unless I synchronize the template, yet the index.html file when edited does sychronize? I cannot seem to find what is set differently!

  • #8 / Sep 26, 2012 8:19pm

    the3mus1can

    426 posts

    The way that I would solve this is by using Sherlock.

    First install Sherlock and then break out the listing loop into an embed (/recipes/.listing):

    {exp:channel:entries category="{embed:category_id}" channel="recipes" status="open" orderby="title" sort="asc" limit="10"}
      <div class="yui-b article">
          <div class="yui3-g">
              <div class="yui3-u-1-5">
                  Image
              </div>
              <div class="yui3-u-4-5">
               {categories limit="1"}
                  <a href="/recipes/{category_url_title}/{url_title}">{title}</a>
                {/categories}
                  {short_introduction}
              </div>
          </div>
      </div>  
    {/exp:channel:entries}

    Next change your conditionals to be like this:

    {embed="embeds/html_header"}
    <body>
      <div id="container"> 
        <div id="wrap">
          <!-- hd -->
          {embed="embeds/header"}
          <!--//hd -->
          
      
          <div class="clearfix">
            <!-- bd -->    
            <div id="bd">
              <div class="yui3-g">
                
                <div class="yui3-u" id="side">
                  <div id="menu">
                    <ul id="treeMenu" class="menu">
                      {exp:channel:categories channel="recipes" style="linear"}
                      <li>
                        <a href="/recipes/{category_url_title}">_                      {category_name}        _                    </a>               
                      </li>
                      {/exp:channel:categories}                   
                    </ul>
                  </div><!--//#menu -->         
                </div><!--// #side --> 
                
                <div class="yui3-u" id="main">
    
                   {exp:sherlock:page_type entry_title_segments="3"}
    
                    {!-- 
                       This should match if it is not a category based url, but is a listing url (which basically means not a single entry url) 
                        ex. /recipes 
                     --}
                    {if is_listing && is_not_category} 
                      <div class="w">
                        <h1>Latest Recipes</h1>
                      </div>
                      <div class="w">
                          {embed="recipe/.listing"}
                      </div>
                    {/if}
                    
                    {!-- This should match if it is a category based url ex. /recipes/italian --}
                    {if is_category && is_not_entry}
                      <div class="w">
                        <h1>{segment_2_category_name} Recipes</h1>
                        {segment_2_category_description}
                      </div>
                      <div class="w">
                        {embed="recipe/.listing" category_id="{segment_2_category_id}"}
                      </div>
                    {/if}
                    
                    {!-- This should match if it is a single entry url ex. /recipes/italian/mommas-spaghetti --}
                    {if is_entry}
                      <div class="w">
                        {exp:channel:entries channel="recipes" url_title="{segment_3}" limit="1"}
                            <h1>{title}</h1>
                            By {author}
                            {short_introduction}
                            {fact}
                        {/exp:channel:entries} 
                      </div><!--// .w -->
                    {/if}
    
                    {/exp:sherlock:page_type}
                  
                </div><!--// yui3-u --> 
              </div><!--// yui3-g -->
            </div><!--// bd -->    
          </div><!--// clearfix -->
    
        </div><!--// wrap -->       
      </div><!--// container -->
    
      <div id="ft">
          <div class="page">
              {embed="embeds/footer"}
          </div>
      </div>   
      
      {google_analytics}
      </body>
    </html>

    Both the is_listing and is_category will still match even if there is a pagination segment in the url. Let me know if you run into a problems.

  • #9 / Sep 27, 2012 4:38pm

    dhjones

    25 posts

    Many thanks, this has worked brilliantly!

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

ExpressionEngine News!

#eecms, #events, #releases