I have created a custom content and trying to use views2 for creating various page views. So i have set-

Sort Criteria:
Node: Post Date, desc

and

Filters such that-
Node Published : Yes
Node Type : my custom content type

This provides me "all" the contents published in my custom content type in descending order of posting date, ie latest published at the top. It works fine for me.

Now if i want to create a page view which shows only the posts submitted today, i will have to add one more filter based on "Node: Post date". When i add this filter, what i need to provide on the "configure Filter Node:Post Date"???
I have tried various options but could not get success in getting, page views for "today's posts", "yesterday's Post", "1 week's post", "1 months Post" etc.
Can anybody please guide me in the right direction.
Thanks for any help.

Comments

Dragolin’s picture

I just tried it out myself and have found the following:

First of all, make sure you have a page display (with url path set) otherwise nothing will show up :)

In filters you add 'Node: Post date' and use the Expose button to show it on your page, make sure you provide an 'Empty text' (under basic settings) to show 'no results' for example, then chose the 'An offset from the current time' to be able to have a dynamic filter using for example '-1 day' for yesterdays posts, then unlock the operator and save! if you view your page now, you'll see a field where you can select 'is equal to' and enter '-1 day' to show all the content types from yesterday ... (use the 'in between' setting for 1 week and 'less than' for older posts)

Of course this is a manual input of the dates!

If you want to set it yourself, then hide the operator again and create seperate views for 'today' 'yesterday' 'this week' etc. and link to them from another page. This works fine for a small set of "date selections" but is not very convenient ...

Better would be to use arguments, the other field in views (similar to filters but more flexible). Now I'm not an expert in arguments at all, but they allow you to set views from the url or page id (if you use path_auto, which you should). You there can set to display your content types from a specific week for example. I'm not sure how to make them dynamic, so you can have yesterday evolving with the current date. Will investigate :)

UPDATE: I found a nice article explaining this for arguments: DrupalSN tutorial and scroll down to sort by date

Dragolin
www.dragolindesign.be

aac’s picture

Thanks for your response.
Filter method works well. But i would be interested to know how can i provide the argument handling code to set the filters for today, yesterday, 1week, 1month etc posts.
What i know is that following arguments should be passed to provide the filters-

1.For today's posts--> Argument is "d" from the current time stamp for node created date (and the operator is "is equal to").

2.For Yesterday's posts--> Argument is "d-1" from the current time stamp for node created date (and the operator is "is equal to").

3.For 1week posts--> Argument is node created date "is greater than" "d-7" from current time stamp.

4.For 1month posts--> Argument is node created date "is equal to" "m" from current time stamp.

5.For 1year posts--> Argument is node created date "is equal to" "Y" from current time stamp.

But i am not able to write a php code to pass these as arguments.

Any help from anybody in this regard will be much appriciated.
Thanks!!

---~~~***~~~---
aac

aac’s picture

I have added an argument-
node : Created date

and set the path to

(base path comes from drupal automatically)/recently_posted/%

Now i am using the following code (without php tags) for one of my cases (for displaying today's posts)-

**************************
$stamp = time() - 86400;  // time stamp for yesterday.

if ( $argument[0] == 'today' ) {
$view->filter[] = array(
  'vid' => $view->vid,
  'tablename' => '',
  'field' => 'node.created',
  'value' => $stamp,
  'operator' => '>',              // filter posts for which node created time stamp > yesterday's time stamp
  'options' => '',
  'position' => count($view->filter),
  'id' => 'node.created',
  );
}

return TRUE;

// IMPORTANT: Invalidate the cached query for this view, as it will need to be regenerated on each request.
$view->is_cacheable = 0;

*************************

Now when i use preview, it shows me following query was run-

SELECT DISTINCT(node.nid) AS nid,
node.created AS node_created
FROM drupal_node node
WHERE (node.status <> 0) AND (node.type in ('custom_content')) AND (DATE_FORMAT((FROM_UNIXTIME(node.created) + INTERVAL 19800 SECOND), '%Y%m%d') = 'today')
ORDER BY node_created DESC

But i am not getting a list of today' post even though there are posts for today's date.
Please point me in the right direction.

---~~~***~~~---
aac

aac’s picture

After so much fight...frustration.....i am still not able to achieve the results...
Is there any Views expert listening this who can help me out??
Thanks for any support!!

---~~~***~~~---
aac

beautifulmind’s picture

I think you can try:
Operator: Is between
Value type: An offset from the current time such as "+1 day" or "-2 hours and 30 minutes"
Min: -1
Max: +1

Regards.

Regards.
🪷 Beautifulmind

aac’s picture

That way it is working fine already.
But in that case i will have to create so many views for each type of listing, one of today's posts, one for yesterday's pasts, one for week's posts etc.
But if i use arguments handling code, then just one view will be sufficient for all those listings.
Anyway thanks for your response.

---~~~***~~~---
aac