Thanks to some spiffy and concise coding by codelust, we've managed to implement voting nodes to the front page in Drupal 6.x at our test site.
You will need the following modules installed:
votingapi
rules
token
token custom
vote up/down
vote up/down nodes (or any voting method that increments votingapi_select_votes)
First you'll need to go to tokens (Administer|Site Building|Tokens) and create a custom token. We went with
Token ID: token_custom_post_vote_count
Description: Count of votes per node
Type: Node
PHP Replacement:
$votes = votingapi_select_votes(array('content_id' => $node->nid));
$rating = 0;
foreach($votes as $vote) {
$rating += $vote['value'];
}
return $count = count($votes);
Then go to triggered rules (Administer|Rules) and add a new rule. We went with
Rule Settings:
Label: Auto Frontpager
Event: Content is going to be viewed
Categories: frontpage
then enable the rule
Finally, under Rule Elements we entered
IF NOT viewed content is promoted to front page
(Label: Viewed content is promoted to frontpage
content: viewed content
check: negate)
AND Numeric comparison
(Label: Numeric comparison
Token Replacement pattern:
Number 1: [node:token_custom_post_vote_count]
Operation: Greater than
Number 2: 5 [note - we promote to front page when nodes get 6 votes. You would change this value according to your needs])
DO Promote viewed content to front page
(Label: Promote viewed content to front page
Content: viewed content
Check "permanently apply changes")
And that's it. We haven't gone live with it at our site yet, but in testing so far it's worked and we haven't been able to break it. We only allow up votes, so there's no logic here to remove nodes from the front page, but with the PHP replacement code in the token it would be very easy to implement.
Obviously this isn't as efficient as a module designed specifically for this purpose, but until one is available this seems to be a decent workaround.
We're posting this to share with the community, there have been a lot of requests for this functionality. We are not developers and are posting this "as is", we're not in a position to provide support or extensive help.
Comments
Started to use this and noticed somethings....
Thank for this writeup, it started me off in the right direction. I found that what worked for me as the replacement text was this:
thanks for the
thanks for the writeup...
have to try it soon..
subscribing
---------------
Andrii Podanenko
CEO, ITCare
Hybrid solution
I'm experimenting with this using the Vote Up/Down module, and found that the trigger was firing in Preview mode, which resulted in duplicate articles, one of which was auto-promoted to the front page while the other acted more or less properly. Plus, neither of the two suggested code snippets quite worked. The following solution seems to do the trick for me:
Rules
Added an additional condition:
which seems to prevent the trigger from triggering prematurely.
Then I fused the two code snippets for the token as follows:
Seems to work!
UPDATE:
I spoke too soon - still getting duplicate posts to the front page when previewing the post before submitting. Grrr. But promotion seems to be working as it should.
What seems to be happening is that the Rule for "viewed content is published" is evaluating to True, even though the post has not yet been submitted, but only viewed as "Preview". That seems to me like a bug of sorts in the Rules module.
FOLLOW-UP:
As a somewhat inelegant workaround to the above problem, added a condition to the custom token to confirm that an actual published node is being viewed. The Rule for "viewed content is published" still evaluates incorrectly (as I see it), but at least the numerical comparison correctly evaluates to "false". Here's what the code snippet looks like now:
So far, it seems to work as it should - however, nodes can only get promoted once they've been viewed at least once after receiving the requisite number of votes.
if (arg(0) == 'node' &&
This works fine for nodes, but I want this for comments. How to?
Thanks ^^
I don't like the way Rules
I don't like the way Rules updates info by default. In my case it added additional tags to the defined node (the reason was in "input formats" but i don't know why it was that way so far).
So I decided to promote the node to frontpage with help of PHP.
I chose "Execute custom PHP code" and there it is:
And now it does what it's expected to do. It just changes 1 table field without all other unnecessary actions of Rules module.
two editors approval/denial needed, how to?
I'm looking for a standardized Drupal module alternative to Independent Media Center modules for Drupal editing.
An editor screen pops-up in Indymedia Alba. Two editors have to give approval or denial before an article is published from the "open newswire" to the frontpage, or 'banned' to "hidden articles" or removed completely.
So a voting module and only editors may vote in this case?
Thank you
Worked for me fine. Thank you.
is this similar to voting
is this similar to voting rules?
http://drupal.org/project/voting_rules