i would like to have a way to select a SINGLE node as 'featured' and then be able to display that on the home page.

i've ben playing around with the sticky/promote to front page, but this doesn't work in a boolean fashion with context to the other nodes. also thought of selecting a node based on sticky/promote and sorted desc by changed date, but other things can change the changed date ...

ie, i would like to have it work so that when one node is set to featured status, the old featured node is disabled. OR if there's a way to add this node to a list of some kind, and then simply select #1 from the list, that's fine too.

any suggestion on how to do this? i'm new to drupal, so bear with the elementary question... thanks!

~queequeg

Comments

arh1’s picture

yeah, good question. i put a hack in place a long time ago to do this on one site, and need to get around to implementing something cleaner and more along "the Drupal way".

you could of course do this with a CCK field, and just write a simple function to query the most recent node with the correct value for that field. that might have seemed like overkill in the past if you didn't otherwise need CCK, but now that much of it is moving into core...

i've also been meaning to play around with the Flag module, which seems like it might do what you want.

queequeg’s picture

thanks for the reply. i have cck installed, but how would i do this with cck? i'm a bit green with drupal ...

i'll try the flag module, but would prefer to figure out how to make it work with what i've got, as i get in the habit of just adding module after module and not learning much about how drupal works!

what i did for the mo was create a table featured_node with one column (nid) and just enter the id for the node .. then i can pull it out on the template, and get the load using the api. but i have not learned how to turn this into an actual module though, and integrate it with the content type! so it's a hack but will figure it out as i go.

any idea how to do this with cck, please let me know. it's my impression that i can't really get use the last modified date on the node table, as when someone makes a comment or edits the node, this date would get updated as well.

arh1’s picture

sorry i can't provide more detail at the moment, but you could create a checkbox field using CCK with a name like "featured" (search the Net or d.o for help with that), and then write a custom function to select the latest node from the db with "featured" toggled on, and display the node.

hth!

queequeg’s picture

maybe i wasn't so clear --

only the uber-admin gets to decide which one is featured. when they set a certain node to featured, whatever was prev. featured needs to be turned OFF. the date modified field is not finegrained enough for this.

so yea, i could add a featured checkbox as you said, and make that only availble to admins, no problem...

but then how can i insert some code into the edit that will turn all the other featured ones off?

something simple, on the receiving end of the edit, when the node is populated from the form and just before updating the database , like (pseudocode) -

if($node->featured){
// set all other nodes to featured = 0
}
// then run the update code for this node and update the database

WorldFallz’s picture

but then how can i insert some code into the edit that will turn all the other featured ones off?

You could probably do this with nodequeue-- if you set the limit of the queue to 1, the previous one will be pushed out of the queue when a new one is added.

Alternatively, you can just use flag and views and set the view to display only 1. This has the added benefit of preserving all the previously featured nodes.

WorldFallz’s picture

This definitely seems like an ideal candidate for the flag and views modules.

dalehgeist’s picture

This is tying me up in knots. The goal seems simple enough: display a list of the most recent news articles, but treat one of them differently (e.g. display more fields) - based on being flagged as "featured".

Try as I might, whether I'm considering a CCK field, a Taxonomy term, the Flag module, or simply the Drupal "sticky" flag, I cannot get around the need to de-flag previously-flagged articles. (Otherwise, how can you exclude the most-recently-flagged article from the list of the most recent articles - flagged or unflagged?) And yet I'm darned if I can figure out how to do that automatically, when a new article is flagged.

I've looked at Actions/Triggers and the Rules module, but all I can see are actions to perform on the "current" node - not "other" nodes.

carl.ben’s picture

as world.fallz said earlier, either nodequeue or a flag/views combo will take care of that for you. It will display only the most recently added item. No need to go back and adjust the previous featured items.

dalehgeist’s picture

Thanks for the reply, carl.ben.

I'm trying nodequeue now, but I'm still not grasping this: how can I display the non-featured articles, excluding the most-recently-featured article, if the non-featured articles can be either flagged, or not?

Remember, this is what I'm trying to accomplish: display a list of recent articles, with one of them treated differently (e.g. more fields), based on it being flagged as "Featured".

dalehgeist’s picture

OK, so here's the goal: display n number of articles on a single page, one of which has been flagged as "Featured" and will be displayed differently from the others (for instance, more fields will be displayed.)

Displaying the Featured article is no problem; there are many different ways to flag it and create a View that returns only the one article most recently flagged as Featured.

The problem comes in with the list of non-Featured articles. I could not find any good way to create that list, and exclude the Featured article, without somehow un-setting the Feature flag of the previously-flagged article. (There are ways to do it if all the articles are flagged, but that's not really helpful here.)

Salvation lies with nodequeue (thanks WorldFallz for that tip).

  1. First, create a queue of one.
  2. Then, create a view that has a nodequeue Relationship. DO NOT REQUIRE that relationship: this allows all nodes into the view. (You'll need this relationship in order to access the Nodequeue filters used in the next steps.)
  3. Create a block (or pane) display for the Featured node and add a filter of type Nodequeue: In Queue, and select "True." Set fields and other filters as desired.
  4. Create another block (or pane) display for the un-Featured nodes. If you left the Nodequeue: In Queue filter as the default in the above step, open it and click "override" (if you used override above, then add a filter of type Nodequeue: In Queue.) This time, select "False." Set fields and other filters as desired.
  5. Create a node and put it into the Featured queue - you can see the results. But the true test comes with the NEXT node you add to the Featured queue: the old one should now appear in your non-Featured list, and the new one will be your Featured one. Voila!

NOTE: If you're using a taxonomy argument, you should use something that comes with the nodequeue module called the "taxonomy smartqueue" - see the nodequeue documentation for how to do this.

WorldFallz’s picture

sorry I didn't see this sooner, but looks like you got it sorted-- thanks for posting back the details, I'm sure it will help someone else. You should consider posting it to the nodequeue handbook pages as well.