1

I want to create a view that only shows the oldest and newest node of a certain content type what is the easiest way to do this?

Thanks

4 Answers 4

2

How about creating a contextual filter in view, and take a look at the below image to select any of these creation dates?

screenshot

Afterwards, filter your content type as in the following image:

screenshot

1

Reader beware: this is probably a bad idea. But I couldn't resist.

function example_views_query_my_view_name_alter(&$view, &$query) {
  $query->addExpression("ABS(nid - (SELECT MAX(nid) + MIN(nid) FROM {node} WHERE type='mynodetype') / 2)", 'horrificorder');
  $query->orderBy('horrificorder', 'DESC');
}

(Of course add a node type filter and display only two items in the Views UI.)

0

"...I needed these on the same view so I can make a calculation..."

Getting calculations generated from Views results will take php coding skill and a knowledge of how Drupal is generating and displaying a page.

0

I guess that you can build two displays, one to show the oldest and other to show newest, and one to show (in each display) only one item per page without pager (in "Pager settings" of your view). Then, you can pull/show/embed these two displays where you need.

3
  • Thanks, but I actually only want to show the oldest and the newest, none of the ones in between?
    – Jeremy
    Oct 27, 2011 at 22:51
  • I guess that you can build two displays, one to show the oldest and other to show newest, and show (in each display) only one item per page without pager (In Pager settings of your View). Then you can pull/show/embed these two displays where you need. I hope have understood well
    – cigotete
    Oct 27, 2011 at 23:02
  • Thankyou, but I needed these on the same view so I can make a calculation between two values that are in the nodes, or can I do this with 2 different views?
    – Jeremy
    Oct 27, 2011 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.