3

Ok so I've got this view, and it has a few dozen items. I want the last 3.

Sort ascending seems to work, however the events are in the opposite order than I want.

Sort descending pulls events back from June.

Is there any way to pull the events, but order them differently with views?

1
  • So basically you want pagination order the way it is, but reverse it inside one page?
    – Mołot
    Commented Aug 19, 2013 at 13:35

2 Answers 2

3

It seems you need to have pages ordered ascending, but inside a page descending. To do that, you need to query database in ascending order. Then reverse order of one page in template that renders it.

<?php

/**
 * @file  views-view-unformatted--yourviewname.tpl.php
 * Default simple view template to display a list of rows.
 *
 * @ingroup views_templates
 */
?>
<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<?php /* foreach ($rows as $id => $row): // That's how it looks by default */ ?>
<?php foreach (array_reverse($rows, TRUE) as $id => $row): /* That's what you need */ ?>
  <div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?>
    <?php print $row; ?>
  </div>
<?php endforeach; ?>
2
  • This broke my view, which has custom styling.
    – Jack Ryan
    Commented Aug 19, 2013 at 17:56
  • @AndrewAlexander Well, here we show the way to do things. We are not going to make your work for you. If your styling wasn't quite ready for reversed order you asked for or if you just overrided previously overriden .tpl you haven't mentioned to us, it's either your concern or a matter for another question. Unless something went wrong in the exact area covered by a question - then I'll be willing to work some more on my answer.
    – Mołot
    Commented Aug 19, 2013 at 18:27
0

To only show 3 items, change the settings in the "pager" section to "Display a specified number of items", and set the number of items to 3 in the settings (assuming you're using Drupal 7). Then you can use a filter of some sort to filter to the exact 3 you want using the post date or any other variable.

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.