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.
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.
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.
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.
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 !
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.
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
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.