Unsticky and Sticky Node Articles

Events happening in the community are now at Drupal community events on www.drupal.org.
kiwipearls's picture

Hey there,

I am finding making rules very difficult.

Basically what I want it to do is once a day check for the last 2 published articles and sticky them, then the next day it will unsticky the previous articles and check for the last 2 published articles and sticky them.

Keeping my featured(sticky) content ever changing.

At the moment I have to manually sticky articles and unsticky the previous two.

I eagerly look forward to hearing from you.

I only want two articles stickied at a time because it looks less intrusive with my theme with just two.

I eagerly look forward to hearing from someone who can help me with this.

Comments

Actually, I'm looking for the

skolesnyk's picture

Actually, I'm looking for the same solution. So far Rules allow changing status of only currently updated/added node. I'm not sure how I can change status of previous (-1 or -n) item. That's what we're both looking for. If I find solution I'll post it here.

Oh Cool

kiwipearls's picture

So we are in the same boat. I'll keep looking for a solution too and will post what I found back here too.

Surely someone out there has done what we want to do already. I even tried finding a module to do just that, but no luck so far.

And everytime I do a google, I only find my posts requesting help on this lol

I think we have to study

skolesnyk's picture

I think we have to study Rules tutorials like this one http://drupal.org/node/520016 . And then make something out of it.

One way of doing it

itangalo's picture

If you're using Drupal 7 (you should!), then one approach for solving this task is:

1) Create a view listing all sticky articles ("sticky-view").
2) Create a view listing the two most recent articles ("recent-view").
3) Create an action set component, with the following actions:
a) Load a list of nodes using a view (found in the Rules Bonus Pack module). Use the sticky-view to load all sticky articles.
b) Add a loop for this list, and inside the loop add an action for making the node unsticky.
c) Load a list of nodes using another view – the recent-view.
d) Add a loop based on this second list, and have an action inside the loop to make each item sticky.

Once this is done, your two most recent articles (and only those) will be sticky every time the action set is run. The last part will be to have this scheduled to happen once every day. This will require Rules Scheduler (found in the Rules module).

4) Add another action last in the action set – "schedule component" (or something like that). Use it to schedule the action set itself at the time "+1 day". This will have the action set reschedule itself over and over again, endlessly.
5) Finally, you need a way to get the endless scheduling started. I usually do this by creating a dummy reaction rule – for example triggering on "content is viewed". Use it to call the action set – which will then make the two most recent articles sticky and also schedule a new update in a day.

Some comments
This is a semi-complex rule, so it might feel a bit confusing. Rules is a complex module, and starting with this pretty complex task might not be the best approach. Sorry about that. There is a pretty good introduction to using Rules Scheduler over at http://nodeone.se/blogg/learn-rules-with-nodeone-part-10-introducing-rul.... It is for Drupal 6, but most things work the same way in Drupal 7.

If you always want the two most recent articles displayed in a special way, then I recommend you doing this with Views – and then applying the styling you wish for that particular view. (Using Views is a whole new chapter, though.)

I hope this might be of some help. Good luck!
//Johan Falk
**
Check out NodeOne's Drupal Learning Library! 150+ screencasts and exercises, for Drupal introduction, advanced configuration, and coding.

Half figured it out

kiwipearls's picture

LOL, I half figured it out, and when I executed it, all my nodes got stickied.

So I must have done something wrong.

Maybe you are right and I should just use my new view I created in the step above and use the recent view to feature my articles.

I'll just need to create a couple of new regions to my theme.

I'm ok with views and will just apply the current sticky css styles to my new region and take it from there.

Just out of interest sakes, here is the export of the rule I created - so I could be told where I went wrong -

"rules_testingfeatures" : {
    "LABEL" : "teastingfeatures",
    "PLUGIN" : "action set",
    "REQUIRES" : [ "rb_misc", "rules", "rules_scheduler" ],
    "USES VARIABLES" : { "testing" : { "label" : "testing", "type" : "list" } },
    "ACTION SET" : [
      { "rb_misc_action_views_load_list" : {
          "USING" : { "view" : "stickyview|page" },
          "PROVIDE" : { "node_list" : { "loadstickyarticles" : "LoadStickyArticles" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "loadstickyarticles" ] },
          "ITEM" : { "loadallstickyarticles" : "loadallstickyarticles" },
          "DO" : [ { "node_make_unsticky" : { "node" : [ "loadallstickyarticles" ] } } ]
        }
      },
      { "rb_misc_action_views_load_list" : {
          "USING" : { "view" : "recentview|page" },
          "PROVIDE" : { "node_list" : { "viewrecentpublishedarticles" : "viewrecentpublisharticles" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "viewrecentpublishedarticles" ] },
          "ITEM" : { "currentpublishedarticles" : "currentpublishedarticles" },
          "DO" : [ { "node_make_sticky" : { "node" : [ "currentpublishedarticles" ] } } ]
        }
      },
      { "schedule" : {
          "component" : "rules_testingfeatures",
          "date" : { "select" : "site:current-date", "date_offset" : { "value" : 86400 } },
          "param_testing" : [ "loadstickyarticles" ]
        }
      }
    ]
  }
}

Limit in the view?

itangalo's picture

Is there a limit to how many items the view should display? There should be an option under "pager" setting, allowing you to have the view list only two articles. I hope this is the problem. If not, then I guess the Rules Bonus action is buggy – please open an issue if that is the case!

Good luck,
//Johan Falk

HI there, yes I put a limit

kiwipearls's picture

HI there, yes I put a limit of 2 for the 2 recent published articles and the sticky view only shows 2, as I only have 2 nodes sticky at a time.

I will keep testing this and see if I can find out if I did go wrong, now that I have a basic understanding of how to do this.

I might just see if the first loop to unsticky works first before moving onto the second loop of stickying 2 from the recent view.

Sounds like a bug

itangalo's picture

If the view displays two nodes only, but the action changes more nodes than that, then I would say this is a bug. I wrote the action myself, and I know there may be bugs there. ;-)

If you put a bug report in, with some steps to reproduce the bug, I'll do my best to get it fixed.

Cheers,
//Johan Falk

TY so much

kiwipearls's picture

Ty so much for your detailed and easy step by step guide on how to accomplish this. There is little step by step guides out there and I watched a view NodeOne Videos but got a little overwhelmed.

I am still implementing this now. I am up to step 3 after installing the Rules Bonus Pack, but just ran into a road block where my two new views were not in the pull down list. But am trying to figure that out now.

Will let you know when I have it working :-)

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: