Hi all,

Been racking my brain on this one for a while. Hopefully someone can help :-)

In Views 2 is it possible to create a view that would display the following:

'There are (x) new items since you last logged in'

Where the above references the number of new nodes published since an individual user logged in and (x) is a link through to a list of the aforementioned nodes.

Any help would be greatly appreciated!

Thanks

Steve

Comments

AvalancheOfLlamas’s picture

This might be a little roundabout but it should work fine...

Add a filter that is Node: has new content
Add some sort of field

Put this in your header/footer:

<?php
$view = views_get_current_view();

// execute view query
$view->execute();

// results are now stored as an array in $view->result
$count = count( $view->result );

print "There are $count new items since you last logged in";
?>
Anonymous’s picture

Not roundabout at all, worked like a charm! Thanks Alan.

Just a quick question. Is there a way you know of to make $count a link to a list of new content?

Steve

AvalancheOfLlamas’s picture

First create the list of new content using a view. The same Node: new content filter should be fine, along with Node: title and (trimmed?) Node: body fields. Make a page display, and give it a path.

Then, you should be able to just add html around your php. For example:

There are <a href="path">
<?php
$view = views_get_current_view();
// execute view query
$view->execute();
// results are now stored as an array in $view->result
$count = count( $view->result );
print "$count ";
?> 
 pages</a> with new content.

I took the rest of the text besides the $count out of the php print statement. The anchor tag <a> surrounds the php and the word "pages", so that would appear as the link.

Alan

Anonymous’s picture

Excellent, thank you very much Alan.

Steve

v8powerage’s picture

Ok now how to print "There are no new posts since your last visit" if nothing's been posted??