Clean URL’s with categories / sub categories
Posted: 10 February 2008 11:46 AM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  115
Joined  01-04-2008

Just going properely with EE in the last few days.

Iv read numerous posts asking for some kind of straight url structure and been experimenting with different methods.

Most of my pages are in the same format so i didnt really see a point in making numerous repeated templates so iv made a kind of ‘oop’ code structure. I understand its advised to use templates to structure data but this to me is cleaner and more ‘resuable’. I could be missing some crucial part understanding of EE though…

Not sure if this is of any use to anyone and there may well be parts that could work better so feel free to post changes, but it may help any newbies out there looking for some kind of quick way to get categories and subc’s working.

http://www.domain.com/category/sub-category/page_url

{embed="file" main_catter="enter root cat id here"}
{if segment_2=="" AND segment_3==""}

{exp
:subcategories root_node="{embed:main_catter}"}
<li><a href="{path="climate/{category_url_title}"}">{category_name}</a></li>
<
p>{category_description}</p>
{/exp:subcategories}

{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="web-pages" category="{cat_id}" dynamic="off" sort="asc"}
<li><a href="{title_permalink={segment_1}/{segment_2}}">{title}</a></li>
<
p>{summary}</p>
{/exp:weblog:entries}

{
/exp:query}

{if
:elseif segment_3!=""}

{exp
:weblog:entries weblog="web-pages" url_title="{segment_3}"}
<h1>{title}</h1>
<
p>{body}</p>
{/exp:weblog:entries}

{
/if}

Pleae post any methods that will work better and feel free to move this to a better section mods. Hope it may be of use to someone

 Signature 

Great EE Podcast

Profile
 
 
Posted: 10 February 2008 02:35 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  671
Joined  06-29-2005

The beauty of this is that is allows one to bring native dynamic=“on” functionality back into a place where dynamic=“off”, for instance, in a sidebar or elsewhere, or anywhere you want to force parsing of the URL structure into a result - OR NOT. I love how it lets you decide how you want the content to display - either dynamically or selectively as determined by whether you pass a variable or not!

What I’m not sure is grasped at this point by you yet, my friend, is that this much of this is the already-built-in functionality of the “big three” weblog tag pairs with dynamic=“on”, if I’m not mistaken. But your code adds a nice tool to the arsenal!

So, the normal tag behavior could simply be applied after the first if:

{if segment_2=="" AND segment_3==""}

{exp
:subcategories root_node="{embed:main_catter}"}
<li><a href="{path="climate/{category_url_title}"}">{category_name}</a></li>
<
p>{category_description}</p>
{/exp:subcategories}

{if
:else}

{exp
:weblog:entries weblog="web-pages" dynamic="on" sort="asc"}

{categories}
{if segment_3
==""}
<li><a href="{path=template_group/template}">{title}</a></li> {!-- where you want the data displayed --}
<p>{summary}</p>
{/categories}

{if
:else}
<h1>{title}</h1>
<
p>{body}</p>

{/if}

{
/exp:weblog:entries}

Does the same thing as what you did, just uses dynamic=“on”, for what its worth. And note the usage of title_permalink=. I generally use path= instead here. You pull the template group and template from the existing url here, but it can point to any template group and template you wish. However, your technique (which self-references the template the link is sitting in) is a nice idea. The category and entry ids would carry over automatically into the refreshed view of the same template.

A nice piece of code! Thanks! I’ll find further uses for this somewhere! I already use hard-coded segment tests to recycle the index page for use as a landing, categories or entries page as you are, but this embedded formulation you’ve come up with is excellent for that!

Terry

 Signature 

Terry Leigh Britton
http://twitter.com/TerryBritton
http://twitter.com/Terr_ee

Search the web using Terry Leigh Britton to find all kinds of stuff I’m into!
Or use Yasni for Terry Leigh Britton

Profile
 
 
Posted: 31 May 2009 11:35 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  659
Joined  04-23-2006

Am I the only one confused by this?

There is no {exp:subcategories} tag!

 Signature 

OLD username was jammo, NEW username is OrganizedFellow

It’s a struggle even to keep focused. This is the best of my AD/HD & GTD.
The exceptionally slow growth of my web dev projects is eclipsed by my patience, understanding and desire to learn AS MUCH AS POSSIBLE as I slowly progress.

Profile
 
 
Posted: 01 June 2009 09:55 AM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  235
Joined  01-30-2007

I think it’s using this 3rd party plugin: http://expressionengine.com/forums/viewthread/27220/

 Signature 

BridgingUnit (EE Pro) | EE Addons | Twitter: MarmaladeToday

Profile
 
 
Posted: 01 June 2009 01:35 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  659
Joined  04-23-2006

@BridgingUnit Thank you, I was totally lost there for a moment.

 Signature 

OLD username was jammo, NEW username is OrganizedFellow

It’s a struggle even to keep focused. This is the best of my AD/HD & GTD.
The exceptionally slow growth of my web dev projects is eclipsed by my patience, understanding and desire to learn AS MUCH AS POSSIBLE as I slowly progress.

Profile
 
 
Posted: 01 June 2009 04:03 PM   [ Ignore ]   [ # 5 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  235
Joined  01-30-2007

@OrganizedFellow - it wasn’t until you flagged it up that I realised that it was out of the ordinary myself smile

 Signature 

BridgingUnit (EE Pro) | EE Addons | Twitter: MarmaladeToday

Profile
 
 
Posted: 17 June 2009 09:50 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
RankRankRank
Total Posts:  511
Joined  11-05-2006

Has anyone had any luck getting “next_entry, prev_entry” to work in the single entry portion of the {if} statement?  I haven’t been able to get it to work.  It seems like EE isn’t recognizing it as a single entry page since the URL is dynamic… or am I missing something?

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 03:47 PM
Total Registered Members: 120459 Total Logged-in Users: 83
Total Topics: 126534 Total Anonymous Users: 40
Total Replies: 665363 Total Guests: 343
Total Posts: 791897    
Members ( View Memberlist )
Newest Members:  lizandermagnosismx2428JordanMartzShaun HardynelsonpowellLimenijetzzyizodiyasmith9822