A solution for promoting multiple content types

Sometimes you need many different content types on a site. And you sometimes need to treat them all as if they were one – for example when making lists in Views. Of all possible ways of doing this, I found one that I really like.

The situation: You have a whole bunch of content types on your site. You’ve given them all unique CCK fields to lower database load. And now the client wants a slick way of promoting content to the front page or the side bar.

The problem: Promoting content can be a yawn, using Flag and Views. But since you have many different content types and many different fields, making a Views list could be a marathon instead of a picnic.

Why? Because you can’t just display the field “introduction text” or “main image” in the content types – they have all different fields. Sure, you can (1) display all the fields from all the content types, and tick the neat box that excludes empty fields. But that would leave you with a view that makes 10x more queries than it has to (and, frankly, the solution is ugly). Another way to go is to (2) make different view lists for every content type, which is no more neat. You can also (3) make two new fields “promotional text” and “promotional image” (and possibly “promotional header”), and share this field on all relevant content types. This would lead to a cluttered node form, fields that would mostly be empty, and reduced database performance.

One solution: The solution I settled for was to make yet another content type, called Promotional pane. (Yes, I use Panels.) The node type includes:

  • A node reference field, with Node Reference URL Widget. The widget displays a link “Create promotional pane” on each content type that can be referenced.
  • A text field “promotional text”.
  • An image field “promotional image”.
  • A default title set to “Promotional pane for insert-referenced-nodetitle-here”.
  • If you like: two flags, “promote to front page” and “promote to sidebar” (but, as said, I like Panels).

An essential part is also Views lists (or panes) for front and sidebar, listing the promoted content. Combine with DraggableViews for a comfortable interface for sorting the lists.

The workflow for using this solution:

  1. Find the content you want to promote. Node type does not matter.
  2. Click the “create promotional pane” link.
  3. Add any promotional text and image you like.
  4. If you use flags, tick either “promote on front page” or “promote in sidebar”.
  5. Save.

Bonus: Visit the admin’s Draggable View and change the order of the promotional panes. (Or have the draggable list displayed on the node page for promotional panes, if you’re an admin.)

Simple to use, nice architecture and no unneccessary load for the database.

Bonus: The views lists displaying the promotional panes should of course not link to the promotional pane, but to the promoted content. But what happens if someone by accident (or on purpose) types “node/123” to reach the node page for a promotional pane?

In the usual case, the visitor would enter a page that doesn’t make much sense (and possibly isn’t themed properly, since it isn’t intended for public view). I avoid this situation by using Rules.

A small rule acts when content of a certain type (promotional pane) is going to be displayed. If the user isn’t admin or so, Rules redirects to the referenced page. (Yes, you could probably use Path redirect or so, but I really like Rules.)

Comments: I’m sure there are many more ways of solving this task, and some of them are likely more neat and more efficient than the one I present here. Please comment on any drawbacks you find, any other solutions you’d like to try, or just drop a line about anything you like.

Kommentarer

Skriv ny kommentar

  • Webbadresser och e-postadresser görs automatiskt till länkar.
  • Lägger till typografiska justeringar.
  • Tillåtna HTML-taggar: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Rader och stycken bryts automatiskt.
  • Du kan skriva kod med <code>...</code> (generiska) eller <?php ... ?> (markerade PHP) taggar
Innehållet i detta fält är privat och kommer inte att visas publikt.