is this at all possible with views? i've noticed there's a node: creation time option in the views filters, but it doesn't seem to support php or any way to build a dynamic date.

Comments

JohnForsythe’s picture

The "Node: Created Time" filter has this help text:

"This filter allows nodes to be filtered by their creation date. The "Value" can either be a date in the format: CCYY-MM-DD HH:MM:SS or the word "now" to use the current time. You may enter a positive or negative number in the "Option" field that will represent the amount of seconds that will be added or substracted to the time; this is most useful when combined with "now". If you have the jscalendar module from jstools installed, you can use a popup date picker here."

So, basically, choose the "Node: Created Time" filter, choose "Is Greater Than" for the Operator, go with "now" in the Value field, and put "-86400" in the Option field. That should show all posts from the last 24 hours (which isn't the same thing as "today", but as close as you can get with views, AFAIK).

--
John Forsythe
Need reliable Drupal hosting?

modul’s picture

Exactly what I did :-) Works like a charm.

niklp’s picture

:) You can build this functionality using Views arguments, thusly:

Create a View, enable page view, select your type/fields as you want. Make sure it has a non-conflicting URL, and note my point about the url construct in the code below. Then in the arguments section, add an argument of "Node: ID" with "display all values" as the default (if no arg is passed, views will assume a list of all nodes that satisfy your remaining views criteria), and in the argument code, paste the following:

//switch (arg(1)) { // this assumes your url will be like "/view-path/<arg>", eg my view path is "timed", to utilise a url of "timed/today", below
// EDIT: the above line, whilst valid, is limiting, in that it force-fixes the value passed to arg() - a better way is to use the views arguments, 
// which I didn't initially use, because I forgot (and couldn't find) the construct used :p
switch ($args[0]) {
  case 'today':
    $today = mktime(0, 0, 0, date("m")  , date("d"), date("Y"));
    $now = time(); // shortens the # of nodes returned as it negates today's as yet unpublished (due to time constraints) nodes (I think :)

    $result = db_query('SELECT nid FROM {node} WHERE created BETWEEN %d AND %d', $today, $now); // fetch today's nodes

    while ($data = db_fetch_object($result)) {
      $nodes[] = $data->nid;
    }
    
    if ($nodes) {
      return $nodes;
    }

  break;
}

And voila! Hopefully... So when you visit the url "timed", you should get a list of all nodes that satisfy your view criteria, and when you visit "timed/today" you will get a list of nodes published (assuming you have that filter) so far today.

It's fairly trivial to add further code to this so you can have other keywords programmed, but there are obviously ways to do date processing in Views anyway, so this and others that cannot be accomplished with Views "au naturel" are niche use cases, really.

Hope this helps - it was a useful exercise for me in views arguments, at least! :)

Nik

Kineta Systems - Web Development in Nottingham

hip’s picture

Hi Nick,

will your solution have anything to do with the event module issue opened here (Ability to have todays events on the front page?).

Spanish Drupal - www.4tres.com : Desarrollo de sitios, páginas web y aplicaciones para Internet eficaces y especializadas en Sevilla.

mooffie’s picture

if ($nodes) {
return $nodes;
}

I'd be surprised if this worked. I think you need to replace that with $args[0] = join('+', $nodes); The 'Node: Id' argument gets a string of NIDs separated by either '+' or ',' (just like a taxonomy selector).

niklp’s picture

I didn't know that! I should have added that I didn't test that extensively, it was just coded ad hoc for someone to help them out.

Kineta Systems - Web Development in Nottingham

MikeMoirano’s picture

Would it also be possible to display whether a node was updated/commented on at the top of a list on the frontpage?

On my site, from the front page you can access a list of all the nodes posted in a time sequential order (nodes are automatically promoted to the front page). I was wondering if, through the views module, or any other means, it would be possible to make a node 'seem new' when it is updated or commented on, so when it is updated or commented on it will go to the top of the list on the front page, thus making the list on the front page a list of all of the recent activity on my site, instead of a time sequenced list of node history. (when a node is update it is buried far back and thus not easily recognized, same with posted on)

Is there another module that could do this, workflow_ng could but I don't know how to make it so things are not stickied on the front page when they are updated or commented on. If anyone could help, I would really appreciate it.

Thanks

cyberswat’s picture

You can do this by creating a view that has these options:

Basic Information:
name = your_name

Page:
check the provide page checkbox
set the url: ex mypage
set view type to teaser list

Filters:
Node Published = Yes

Sort Criteria:
Node: Updated Time = DESC or ASC depending on your preference.

When your done navigate to the equivalent of http://localhost/mypage in your environment

Quick edit ... there is also a Comment Last Comment Date available in views

MikeMoirano’s picture

So if I add three values in my sort criteria (node: updated time, comment: last comment date; node: created time), what is going to happen?

I think I may have tried this before and it wasn't what I expected. I'll try it out but I'm not sure this solves the problem.

Update: It doesn't work.

What the sort criteria does is first list all of my updated pages, then lists all of my nodes with comments, then lists the newly created nodes.

I am trying to keep my front page list in an order that will list the time ordered activity on my site, so when anything happens (a node is created, a node is updated, a node is commented on), the list from the front page will keep an order of all of the activity on the site, with the most recent at the top of the list. (I am using a page view- I am trying to display only a list of ten on the first page and then all the older nodes on the subsequent pages, still all of them on the 'frontpage')

niklp’s picture

I think you should post a new topic for this, it's not really related to the subject of the initial post.

Kineta Systems - Web Development in Nottingham