Using Editable Fields for Featured Content Blocks in Drupal 7
It is a common requirement on a marketing website to have a “Featured Content” block on the homepage that displays some random node from a subset of content that has been flagged as featured. There are a number of modules that try to address this type of functionality, but I’m always a fan of using fewer modules — or at least using modules that can be used in many places.
Real World Example
I recently built this kind of functionality on a real estate website. The client wanted a block that displayed a single random property, but not from all of the properties, just the ones that he flagged as featured. I accomplished this easily by adding a checkbox field to the property content type that says “Feature this property on the homepage.”
Building the Featured Content Block
The view that displays the featured content block is simple.
Filter criteria:
- node is published,
- content type = property, and
- featured = Feature this property on the homepage
Sort criteria:
- global: random
Then add the fields you want to display and you are done.
Managing the Featured Content Block
There is one aspect where I feel that building the Featured Content Block this way breaks down. When the client is managing which properties are featured or not they need to go into each property to check or uncheck the featured field.
The first step to solving this hiccup is to create a second view that displays a table of all the properties on the site and their featured/not featured status. This gives you a bird’s eye view of the featured content but still doesn’t make it easy to change the featured content.
The next step is to install the editablefields modules and make the featured field on the view “editable.” This module makes the featured field show up as a checkbox when the view is displayed. Now the client can check and uncheck all of the properties where they want to change the featured status and save the page.
As with most tasks in Drupal there are many ways to accomplish the same goal. This solution to the featured content problem works well for me because it uses many of the same techniques used elsewhere in the site with the exception of the editablefields module. However, this module can have alternate uses on the site and it is lightweight.
Related Content
MONTHLY MARKETING INSIGHTS.
Get thought-provoking and actionable insights to improve how your firm makes a connection with your customers.
LEAVE A COMMENT
Maybe creating custom Views Bulk Operation (featured/unfeatured) will be better solution dont you think?
But wait I totally forgot iToggle module (http://drupal.org/project/itoggle) other method to achieve same result.
Drupal has many ways to same result :-)
We use it for a home-grown ticket web app. The module works really well for drop down selects. Although it gets a little wonky on text area fields, but their working on a fix here.
Other than that, the module is pretty solid.
In those situations, I usually create a taxonomy, even if there is a single check box.
I call it "promotion" or something like that.
Because very often, client come back and asks "Can you make a second area like the one you made on the homepage, but with other properties, that we would choose separately and show on the contact us page".
With this, I just add a second term called "promoted on contact page", and add the corresponding view.
This way, clients can check the right boxes under a single "promotion" field.
@Pari: VBO would be an excellent way to accomplish this type of functionality if we are managing the site for the client, but I don't typically like giving clients permission to something as powerful (read dangerous) as VBO. The iToggle module looks pretty nice though. I may have to give it a test run the next time I need this functionality.
@Jon: Thanks! That's a great idea too.
@Philippe Jadin: Sure. There is nothing that says that the "featured" field has to be boolean. Although, I personally wouldn't add all the baggage that comes with a taxonomy, when you could just make a list(text) field with checkboxes in the content type and accomplish what you are describing.
I tend to run away from taxonomies as fast as I can except for very specific cases like "free tagging" with tag clouds. There are way too many things that taxonomy does that have to be undone when the same can be accomplished more simply with a node reference field or a simple default list of values in most cases. (sounds like material for another post)
I've used the exact same method you did for a featured content block. A pat on my own back for figuring that out as a novice Drupal user.
The issue I have is how to prevent the node in the featured content block from displaying in my other view.
My real world situation: I'm building a news site. Some news articles are headlines and others aren't. So one headline (checkbox in the node type as you described above) is in my featured content block. Now I don't want the same node to display in the (chronological) view below.
Since some articles are headlines (featured content) and others aren't, I can't simply exclude the last node from the view. This is easy but a news article about a street party isn't as important as a shooting. Now when the article about the shooting (featured content) is older than the other (non-featured) article, I have no idea how to exclude the featured article from my chronological view. Any ideas?
@Bert: What kind of field did you use for featured? If you have one view that selects when true, is it possible to have the chronological view select when null or false (depending on the field)? Am I misunderstanding the issue?
@JD Collier: To clarify my case: I have a big headline article on my home page and below all the articles in chronological order. So an article is a "content type" and some articles are checked as "headline" which is a custom field check box in the content type. Obviously, if you have one large headline article above, you don't want to repeat that same article right below (or a couple of teasers further down). This way it's possible to publish new content and specify whether it's important enough to put in the spotlight as a "headline" article or not.
I don't think your suggestion is the right one for my case. Because I can't restrict the chronological view with only "headline" unchecked or checked. Then I would hide all the headline articles while I only want to hide a specific one (in the featured content box).
After weeks of googling, I actually found a solution. There's a module called Views Exclude Previous. This is a views filter that detects which nodes have already been loaded on the page. There are a couple of options possible and one of the options worked for me.
http://drupal.org/project/views_exclude_previous
For Drupal 7 it's still a development version but it works fine for me. Maintainers are asking to test it.
Hopefully someone can use this experience.