June 15, 2012
ExpressionEngine Pagination with Structure and Zoo Triggers
Using Structure with ExpressionEngine is one of the most client-friendly things you can do for your EE sites. It allows you to set up a nice tree view of your site content, complete with drag & drop, page additions, and a slew of nice display functions for the front end.
One big sticking point when using Structure is that it overrides your default EE URL system, which can be troublesome when you want to get things like categories and date based archives working within Structure.
Say you want to set up a WordPress-style date/category area of your site, like a blog or a news area. When I first got this working within Structure, it required a ton of ugly PHP to check segment values and display different content based on the results. Not very elegant and inefficient. I knew there had to be a better way.
After looking around for some solutions, I stumbled across Zoo Triggers. From the developer:
No more fiddling around and wasting time trying to get categories and archives to play nice with your Structure setup. Zoo Triggers is the add-on that fills the gap between Structure and ‘categories and archives’. Within seconds you have ‘category, archive and tags’ filters on your base Structure install.
You can read more about the Zoo Triggers setup on their site, but it is dead simple. You just add a simple tag to your channel entries loop and it will automatically update your entries based on the URL. They even have handy Category and Date based tags to output your sub navigations. These come with a bunch of options to tailor your sub navigation to your site. The documentation could use some updating, as a bunch of options are not currently described. I’m sure this will be updated soon.
Using Zoo Triggers with Structure works remarkably well. Your entries are all controlled through Structure (as a listing beneath a main “blog” page). All you need are two templates. One template (blog_list) for both the main page and any date & category listing pages. This one page simply gets updated based on the URL structure to show the appropriate entries. Then a second template for the single entry page. You could probably do it all in one, but I like the separation. Set up your listing in Structure and then set the default template for the listing entries to be the single entry template (blog_single). Then just insert the navigation tags you want to use and you are pretty much done.
NOTE: Make sure you do NOT have Dynamic Channel Caching on. If you do, the pagination will not work. I’m not sure if this is a by product of Structure, Zoo Triggers, or just a problem with EE, but it tripped me up for a while. Basically the query for the first page gets cached and when you visit any other “page” in the section, it just shows the original entries that were cached. You can turn it off in Admin > Channel Administration > Global Preferences.