Three Tier Static Content in ExpressionEngine - Approach D

Here’s a fourth way to build navigation for static content in ExpressionEngine, using one weblog, one template, no categories, and relationships.  Previously I’ve posted 3 other ways to do this on a mini-site.  The advantages to this newest approach is everything can be contained in one weblog, using one template, no categories, and one relationship field.  Here’s a working example of this approach.

 
Download the EE Code for Three Tier Static Content in ExpressionEngine - Approach D

This method builds nicely on the “Approach-A” I’ve outlined previously.  Here’s what you need to add:

  • Another custom field, named “static_parent_page”.  Make this a relationship field and specify the same weblog as this fieldset is already used in.  Stick with the default for title, and save the new field
  • Now go through your content entries, and edit the second-level pages, assigning them to the parent-level pages.  In my working example I have seven entries.  I left the index entry alone, and edited pages two, three, five and six to assign them to either page one or four - which I’m arbitrarily making my second-level pages.


The Code
The nav-building code is a bit more complex in this case, so lets take a look at the text version of the template and go through the code.

  • The main weblog:entries tag that builds the left nav is unchanged from Approach A
  • The first conditional looks at the value of the new static_parent_page field. If this is 0, that means there is no relationship setup, so this must be a parent page.
  • Each parent page gets an opening li, then the code uses reverse related entries to pull in all the pages that list this page as parent.  Reverse related entries is necessary because we estabished the relationship from the perspective of the child
  • The code uses two EE variables, count and total_count, to determine when to insert the nested opening and closing ul tags.
  • Once the reverse_related_entries code is done, the closing li tag for the parent item is added.
  • The weblog entries tag closes and then the overall parent ul tag is closed.

The Results
The results of this approach can be seen in the working example, which renders with an index entry that’s omitted from the left-nav (the top-level of content), and a navigation bar that has two levels of pages.  The second level links are pages with no relationships established thereby making them “parents”, and under each parent is a nested UL with it’s children (the entries where we specified a parent page). 

Advantages

  • Simplicity in terms of EE setup - using only one weblog and one template
  • Better usability for clients—the parent_page field appears on the Control Panel Publish form along with other fields, vs. the categories which depend on users remembering to click to another tab to assign.
  • Consistent interface for content maintenance—all using the weblog Publish page, vs. using categories where category pages have to be edited in the category interface where there is no file upload function, etc.

Disadvantages

  • Subpage URL structure is the same as Parent Pages—so the nav structure is not reflected in the URL structure.
  • The Parent Page drop-down won’t reflect any structure, so this approach is probably best for smaller less complex sections of content.

Overall I think this is still my favorite approach for static three-level content in EE - especially when the structure can be filled in by the site developer before the client is unleashed on the site.

Category Navigation

<< Previous Entry   

Next Entry >>

 

Previous Comments

Picture of joshclark17

by joshclark17

Date: Wednesday, July 23rd, 2008
Comment: #1

Hi Mike-
What if I want to add the relationship field and apply it to multiple weblogs each referring back to itself for the relationship? There is only a radio button for relating it to another weblog or to a photo gallery. You’re thoughts?

Josh

Mike Boyink

by Mike Boyink (Author)

Date: Wednesday, July 23rd, 2008
Comment: #2

Hey Josh - I don’t completely understand the question.  If you’re asking can one field establish multiple relationships the answer is no - not with out of the box EE.  If you want multiple related items you have setup multiple fields.

There are a couple of 3rd party extensions that will do that.  One requires a hack to an EE core file and the other I have not used.

Picture of joshclark17

by joshclark17

Date: Wednesday, July 23rd, 2008
Comment: #3

Sorry- I didn’t make myself very clear. What I’m trying to do is apply a single Custom field group to multiple weblogs which should look inward for the relationship. For example, I have one custom field group, called “static pages” which I have applied to 4 weblogs, “sectionOne”, “sectionTwo” , “sectionThree”, and “sectionFour.“

There doesn’t appear to be a way to use a single custom field group for all of these, because you have to set up a relationship with a specific weblog, rather than just telling the system to choose the weblog that the field group is applied to.

Does that make sense? Thanks a ton!

Mike Boyink

by Mike Boyink (Author)

Date: Wednesday, July 23rd, 2008
Comment: #4

Nope - you’ll need a dedicated field group.

Picture of joshclark17

by joshclark17

Date: Wednesday, July 23rd, 2008
Comment: #5

Thanks Mike. Not the answer that I was hoping for, but an answer nonetheless. Your tutorials are very helpful. Thanks for sharing your knowledge.

Picture of Leslie

by Leslie

Date: Wednesday, July 30th, 2008
Comment: #6

Hi Mike, thank you for all the fantastic information. I’m always scouring your stuff. :-)

You mentioned a few third party extensions that allow for multiple relationships to one field. I have a client that I’m setting up authors and books as seperate weblogs and relating them but some authors have multiple books and other books have multiple authors. I did some research to find those extensions but wasn’t successful. Do you mind passing along those URLs?

Again, thank you!

Mike Boyink

by Mike Boyink (Author)

Date: Wednesday, July 30th, 2008
Comment: #7

Hey Leslie - there’s really only one, and the one thing I don’t like about it is that it requires a hack to an EE core file.

The support thread for it is here.

Picture of BiL

by BiL

Date: Tuesday, August 19th, 2008
Comment: #8

I had developed a site with just one level using one entry for page content. Client wanted to created pages on an additional sub level. Thought I was screwed till I found this. In no time I had the relationships setup, made super-minor changes to my templates and bang - works like a charm. Thanks!

Mike Boyink

by Mike Boyink (Author)

Date: Tuesday, August 19th, 2008
Comment: #9

Thanks for the comment - glad to hear it!

Mike Boyink

by Mike Boyink (Author)

Date: Friday, September 5th, 2008
Comment: #10

BTW - check out SolSpaces site - they are advertising a new addon for multiple relationships.

Picture of Leslie

by Leslie

Date: Friday, September 5th, 2008
Comment: #11

Hey, very cool! Thanks! I actually got that client set up already but I’m sure it’ll come up again. I appreciate the info!

Picture of Brian Lokker

by

Date: Thursday, September 18th, 2008
Comment: #12

Mike, is there a way to indicate the “current” page in the menu when using this approach? Thanks.

Mike Boyink

by Mike Boyink (Author)

Date: Thursday, September 18th, 2008
Comment: #13

I think you could add:

{if segment_3==url_title} class="active"{/if}

to both places where the link is specified, and style the active class on the link.

Picture of Brian Lokker

by

Date: Thursday, September 18th, 2008
Comment: #14

Thanks. I’ll give it a try. This method looks promising for my current needs.

Picture of Brian Lokker

by

Date: Friday, September 19th, 2008
Comment: #15

This works, except when a link to a parent page is highlighted as active, all child page links are also highlighted. (Not the reverse, though.) Any further thoughts? If I’m on a parent page, I’d like only that link to be active.

Mike Boyink

by Mike Boyink (Author)

Date: Friday, September 19th, 2008
Comment: #16

Hey Brian - I tried it and it appears to work OK. I had to put the conditional in both the main weblog entries link and the related pages link.  Here’s a text version of the updated template.

Picture of Brian Lokker

by

Date: Friday, September 19th, 2008
Comment: #17

Mike - you’re right. I had put the conditional on the li tags rather than on the links themselves, so when the parent list item was marked as active, the children inherited the class. Putting the conditional on the a tag works like a charm. Thanks!

Brian

PS Sorry I missed your training sessions. I would have loved to be there, and I’m glad to hear they were successful.

Mike Boyink

by Mike Boyink (Author)

Date: Friday, September 19th, 2008
Comment: #18

Yep - I first thought of doing the li tags, but figured inheritance might pop up.  Glad to see the link-based approach works.

Stay tuned on the classroom training. We’re scurrying trying to get a more southern destination figured out for a possible November class.  The window is short, however so we might not make it until January.

Picture of Brian Lokker

by

Date: Friday, September 19th, 2008
Comment: #19

Actually I would have loved to come to Holland - I used to live in GR and have friends there and in Grand Haven. But another location could work too.

Picture of Andy Foster

by

Date: Thursday, October 9th, 2008
Comment: #20

This is a great tutorial. It helped my situation greatly.

I do have an issue that I found odd.

Using url_title_path caused my links to insert the ‘somethingindex.php’ instead of a clean URL. It drove me nuts.

Note - I am not using the default index.php but had to rename it and now am stuck with it.

Any suggestions?

Thanks

Mike Boyink

by Mike Boyink (Author)

Date: Friday, October 10th, 2008
Comment: #21

Hi Andy - I’ve renamed index.php on quite a few sites (Train-ee included) and am still able to use the url_title_path variable.  Did you change the “Name of your site’s index page” setting under Admin > General Configuration?

Otherwise you can build your links in a more manual fashion by hard-coding parts of the path, using the site_url variable, and url_title from the entry.

Picture of Andy Foster

by

Date: Friday, October 10th, 2008
Comment: #22

Hi Mike -

I looked at that and no luck.

I did solve this by using the site_url and url_title and it seems to be the best solution for me.

It’s fine as I only use one template page per template group so it’s not too cumbersome.

Thanks and this tutorial is great also - much appreciated for taking the time to share this.

Add Your Comment

Comment on this Post

  

Unless otherwise stated all content is © Michael Boyink of Train-ee.com & Boyink Interactive. Please don't steal - I've got kids to feed...