views:

371

answers:

2

I am trying to add some additional logic to the 'Promoted to front page' feature in Drupal 6. That is, rather than the boolean behavior there by default, I would like to add additional criteria that a node must meet before appearing on the home page.

Specifically, I don't want past events (as determined by a CCK Date field) appearing on the home page even if they are promoted.

Is there a way I can replace the content produced by node_page_default()? The SQL there isn't dynamically generated, so I imagine the output would need to be replaced entirely.

(I realize that all this could be accomplished via Views, or maybe hook_cron, but I would prefer not to use those methods for a relatively minor quirk.)

Thanks in advance!

+4  A: 

As node_page_default() calls db_rewrite_sql() on the query, you might try implementing hook_db_rewrite_sql() in a custom module to add your additional restriction. I do not recommend this, as you'd need to somehow recognize the original query in your hook implementation, and this would be fragile - other modules might rewrite it also, and it could change anytime with an update, thus breaking your change.

Alternatively, you could create your own version of node_page_default() by copying it to a custom module, modifying it as you need (don't forget to rename) and then implement hook_menu_alter() to swap the original page callback to node_page_default on the 'node' path with your customized version. (You could also register your own frontpage path using your customized callback via hook_menu() and adjust your frontpage setting to point to that one.)

But in case you already use the views module in your site, I'd recommend saving all this work and just enabling the provided override for the frontpage view, adjusting its filter settings accordingly.

Henrik Opel
+1 for Views module. WAY easier!
theunraveler
Thanks! I suspected Views would end up being the best solution, but was holding out hope that I could avoid having to deal with a separate admin UI for this.
anschauung
A: 

I realize this has already been answered, but you probably do want to do this with views.

If not views, then I'd go with changing the front page path, and creating your own page via hook_menu() and implementing it there.

John Fiala

related questions