Section Fronts: with some help from Views Arguments Extras

Section Fronts can mean a lot of different things. But in general they are a page that aggregates stories around a topic or section. I will run through using the Views Arguments Extras module to easily implement a section front concept in drupal.

Erik Summerfield, Director of Engineering
#Drupal | Posted

Section Fronts can mean a lot of different things. But in general they are a page that aggregates stories around a topic or section. I will run through using the Views Arguments Extras module to easily implement a section front concept in drupal.

Problem

We want to have a section front that has two list, one of blog post and one of article posts. We want this list to be limited by a taxonomy term, we want to "promote" particular articles to be at the top of the section and we want control over the order of the promoted items. We also want to create new section fronts easily and quickly.

Solution

As we want to the ability to create these quickly and easily it makes sense to have section fronts as a content type, and to some how set it up so all one has to do is create a new node and they get a new section front.

If we do this we have a good place to store the taxonomy term to use as well as which story/blog nodes we want to promote, as we can use cck taxonomy to store the term and cck node references (which let us order) for the promoted blog and story nodes.

So now the hard part how do we get that information into views? While there are ways using view relationships, a new module Views Arguments Extras Module makes it a little easier.

Views Arguments Extras: Default Argument

Views Arguments Extras

enables a new argument default type "CCK field Value from Current Node" (you might have used the other default type to get the currents nodes nid or maybe to insert some logic with php). This gives us direct access to the cck field that holds which taxonomy term to use and which nodes to promote.

Lets Create the view for Stories. First, we add a 'Taxonomy Term ID' argument to the view. While setting it up we use Views Arguments Extras new default argument "CCK field Value from Current Node", to pull the term id from the field_section_term cck field.

This will limit the articles to those from the correct Topic. But how do we get the promoted entries to appear at the top?

To do this, you need to combine a cck field default setting and a new sort option called "Arguments: Multi-item Argument Order" that is provided by Views Arguments Extras.

We need to pull in the values from the field_section_prom_story but we do not want it to limit the view (like most arguments do) so we create a Global: NULL argument. When setting it up we use the default argument "CCK field Value from Current Node" to pull the nids from the field_section_prom_story cck field. We set the delta setting to 'all', this will pull all of the nodes list in a comma separated list.

So now the data is available to the view, but we want these items at the top of the list and sorted. This is where Views Arguments Extras new sort: "Arguments: Multi-item Argument Order" comes in.

Views Arguments Extras Sort - Arguments: Multi-item Argument Order

Views Arguments Extras new sort: "Arguments: Multi-item Argument Order" allows us to sort our view based on the order of the nids in an argument. Because we are pointing the sort at a Global:NULL argument type, we have to say what kind of data is in the argument (in this case nids);

Now the promoted entries will appear on top with the rest of the stories below. You can do the same for the view that pulls your blog entries.

One can use panels or context, or code in the tpl file to place the views on the node page, and we have Section fronts with promotable content, the data stored in a logical way, and easy maintenance.

Erik Summerfield

Erik Summerfield

Director of Engineering