We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Structure module - categories

Development and Programming

Andy Harris's avatar
Andy Harris
958 posts
16 years ago
Andy Harris's avatar Andy Harris

I’m really struggling getting categories to play ball on my Structure site, and I’ve now been looking at it for too long so am probably missing something.

I have a page created at http://example.com/testing-analysis/ which renders as expected. It’s a list page, and the list works complete with pagination. All cool.

I have created a list of categories related to the list, and if I try to access http://example.com/testing-analysis/category/electronics/ I get a blank page.

I was hoping to see the same page as http://example.com/testing-analysis/ so I can simply add in a conditional to handle the list if ‘category’ is detected at {segment_2}, but no dice.

Any suggestions as to what I’m doing wrong appreciated as always - cheers guys.

       
Tyssen's avatar
Tyssen
756 posts
16 years ago
Tyssen's avatar Tyssen

My understanding of Structure might be wrong, but it doesn’t really work with categories in the way EE natively does, ie, it doesn’t trigger a category with a key word in the URI. In structure you’d need to have testing-analysis set up as a parent page with category as a subpage and then electronics as either a subpage of that or as a listing.

So if I was doing a site with Structure, I wouldn’t bother having a segment that says category as it doesn’t say anything about the content it’s displaying. Instead, you’d replace category with the name of the subsection, e.g. products.

You also have to make sure that each page/listing has a template assigned.

       
Andy Harris's avatar
Andy Harris
958 posts
16 years ago
Andy Harris's avatar Andy Harris

Cheers for the reply. That’s kind of what I’m doing - I’m including category in the URL simply so I can detect if we’re wanting to use categories. I’ve tried creating a subpage called http://example.com/testing-analysis/category/ which appears OK, but then when I go to http://example.com/testing-analysis/category/electronics/ I get a blank page.

If I could use my ‘category’ subpage and grab the segment_3 so I can filter the list by category, that would work and I’d be happy. Surely I don’t have to create subpages manually per category as that makes structure a bit lame.

       
Tyssen's avatar
Tyssen
756 posts
16 years ago
Tyssen's avatar Tyssen

It’s a bit hard to get a picture of what you’re trying to do without seeing how you’ve set your structure up.

       
Andy Harris's avatar
Andy Harris
958 posts
16 years ago
Andy Harris's avatar Andy Harris

I’m not sure how I can describe it any better…I could give you a CP login if you’d be so kind as to take a look, I’m bashing a brick wall with it.

The setup for that page is as simple as : (without the category subpage in this case)

       
Tyssen's avatar
Tyssen
756 posts
16 years ago
Tyssen's avatar Tyssen

I’ll have a look if you like although I can’t guarantee I’ll be able to provide an answer.

       
Andy Harris's avatar
Andy Harris
958 posts
16 years ago
Andy Harris's avatar Andy Harris

I shall DM you the details, and no worries at all about the answer - it might just be something simple I’ve missed.

Thanks for looking, owe you one.

       
Benjamin David's avatar
Benjamin David
77 posts
16 years ago
Benjamin David's avatar Benjamin David

Hi Andy, I’m playing with structure and I wanted to do exactly the same thing as you. I can’t find any way to integrate categories with structure the way you tried.

I was wondering how you ended up with this thing ? Have you manage to do it ?

Thanks for hepling !

       
Andy Harris's avatar
Andy Harris
958 posts
16 years ago
Andy Harris's avatar Andy Harris

Hi Benjamin,

I got this working in the same way as Structure handles (or appears to handle) pagination - by passing it as a querystring rather than a native EE segment.

So for example instead of http://example.com/testing-analysis/category/electronics/, I’m using http://example.com/testing-analysis/?cat=electronics.

Then I’m picking it up in the template with PHP and using a custom SQL query to handle the hard work. It seems to work OK, so far!

Hope that helps.

       
Benjamin David's avatar
Benjamin David
77 posts
16 years ago
Benjamin David's avatar Benjamin David

Hi Andy ang thanks for your reply !

It seems like a good way to make it work without needing to hard code anything, that’s nice !

Yesterday I kept on thinking about it and I may have found some other way to make it work (I’m still working on it). Here is the idea :

Structure URL (uses portfolio-tpl template) http://example.com/portfolio/

Categories URL http://example.com/portfolio-tpl/category/websites/

and to add few lines in the HTACCESS :

RewriteRule ^portfolio/(.*)$ /index.php/portfolio-tpl/category/$1/ [L]

(Not sure this is exactly working but you get the idea)

to make the same URL work this way : http://example.com/portfolio/websites/

I’ll tell you if I get this to work, but I’m already wondering how I’ll be able to get the parent entry from the categories page. As Structure doesn’t use the url_title, I’m wondering what kind of query I’m gonna have to make to find the portfolio structure entry from the term “portfolio” (when I’m on a category page).

Anyway, I’m gonna try this a little bit and if it still doesn’t work, I’ll setup a querystring solution like yours.

Thanks for your help !

       
Andy Harris's avatar
Andy Harris
958 posts
16 years ago
Andy Harris's avatar Andy Harris

Hi Benjamin - did you ever get this way to work? I’m back onto a Structure site faced with categories again, always seeking better ways!

       
rockthenroll's avatar
rockthenroll
485 posts
16 years ago
rockthenroll's avatar rockthenroll

Passing a string is a great way to do this. I’ve been meaning to write an article about it. Also, remember you can always switch to the normal templating system just to feed data through the front-end. Sometimes there’s no reason to have the category page in Structure at all as it’s purely a sorting mechanism. You can attach a listing to a main page for authors so they have the simple interface, but how you display them on the front-end can be different.

       
code72's avatar
code72
104 posts
16 years ago
code72's avatar code72

I was able to get categories work with Structure by putting a conditional in the “dynamic” parameter. For example:

{exp:weblog:entries weblog="portfolio" dynamic="{if segment_2 == 'category'}on{/if}{if segment_2 != 'category'}off{/if}" disable="member_data|pagination|trackbacks"}

-John

       
rockthenroll's avatar
rockthenroll
485 posts
16 years ago
rockthenroll's avatar rockthenroll

@code72 Great solution! Have you tested this deeper than 2 levels?

       
Andy Harris's avatar
Andy Harris
958 posts
16 years ago
Andy Harris's avatar Andy Harris

Be sure to check out this excellent write up of Structure:

http://www.viget.com/inspire/a-whole-new-wooooorld-structure-expressionengine

It suggests using a combo of Leevi Grahams Safe Segments and Lows Seg2Cat, and I’ve gotten my categories to fire much more neatly.

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.