ExpressionEngine Training by Boyink Interactive

Learn ExpressionEngine® Fast

 
By Mike Boyink on July 16, 2008 in Static Content    (9) Comments

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.

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

  • Another custom field, named “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 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.

Series Navigation

Next entry: Mixing Other Templates into Static Navigation

Previous entry: Three-Tier Static Content in ExpressionEngine: Approach C

Previous Comments

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

#1 by joshclark17 on July 23, 2008

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.

#2 by Mike Boyink on July 23, 2008

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!

#3 by joshclark17 on July 23, 2008

Nope - you’ll need a dedicated field group.

#4 by Mike Boyink on July 23, 2008

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

#5 by joshclark17 on July 23, 2008

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!

#6 by Leslie on July 30, 2008

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.

#7 by Mike Boyink on July 30, 2008

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!

#8 by BiL on August 19, 2008

Thanks for the comment - glad to hear it!

#9 by Mike Boyink on August 19, 2008
Page 1 of 1 pages

Add Your Comment


Name:
Email:
URL:

Remember me?

Shoot me an email when someone responds?

Enter this word:

Here:

Checkout Requirements

In order to make a purchase from Train-ee you’ll need to first be registered and logged in, and you will also need a PayPal account.

Links to the downloadable files will be sent upon receipt of payment.

Note that if you pay with a credit or debit card and PayPal sees the transaction as an “eCheck”, there will be a 3-4 day delay before the transaction completes and you receive the download links.

Categories

Church Website Project

Feed Me