By elife2 on
the problem is with displaying a nodes from a custom module in different orders (by title, total votes, chronological...).
I tried to do it inside hook_load with for example
db_fetch_object(db_query('SELECT nid, title, value FROM node
LEFT JOIN votingapi_cache ON (content_id=nid)
WHERE vid = %d AND function="count" ORDER BY title ', $node->vid) );
but the nodes would not be sorted by title at all. Tried db_rewrite_sql and it did not help too. Would someone point me to the right direction please? is hook_load where the sort should happen?
I would rather not use the views, less dependant on add ons better.
Thank you.
Comments
The hook_load is the hook to
The hook_load is the hook to tell drupal witch extra fields he can use to display the node.
I don't think you can do it by a hook.
Perhaps you can take a look at the views module. There you can add a view that display all the nodes of your node type and you can define your own sort criteria.
thank you Passero. I checked
thank you Passero. I checked the views, but it seems voting api fields are not available in views.
There must be a way to do this, how for example vote_storylink module in vote up down package manages to present nodes by number of votes etc. without the views.
Check the source
Check the source of a module that does it :)
When i was developing on my module i checked lots of other modules for examples.
Turned out to be too
Turned out to be too complicated and time consuming vote up down being an integration to links and story modules.
Ended up modifying function node_page_default function directly. I know pro durpalers would not like this kind of things but does the work.
Thank you Passero
Perhaps a better solution
Perhaps a better solutions is to let the views module know witch field and tables it can use for that specific node type.
I created a module of my own and i needed that field in my views. Therefore i used the hook hook_views_tables
If you just implement this hook for the module you want to sort, than you can use those fields in the views module.
THis is more flexibel.
If you like, i can help you on this, just let me know what field and what module and i'll have a look at it.