1

Sorry for the cryptic title, but could not find a better descriptive title. Suggestions welcome.

Situation: There is a newssite with on the frontpage two blocks:

1) a block of the latest 6 'promoted to frontpage' articles in form of an image caroussel
2) a block with the latest 12 newsheadlines, contains both 'promoted' as 'regular' articles

What should happen is:

  • block one displays the latest 6 'promoted to frontpage' articles
  • block 2 does not only contain older 'promoted to frontpage' articles, but also regular articles
  • when an article shifts out of bock 1 it should shift towards block 2, assuming it is not older than the 12th article in this block
  • there should be no overlap in articles between block 1 and 2, ie: the articles displayed in block 1 should not be displayed in block 2

Problem:

The problem is block 2. I can't figure out howto establish what I want without having an overlap between the two blocks.

The view of block 2 is pretty easy: select 12 nodes of the type 'article', order by date.

Question:

But how do I make sure that this selection takes out the first 6 promoted to frontpage articles? Offset 6 won't work, because then it might also skip regular articles. Only the promoted articles should be offsetted.

Is this feasible with some custom php code?

--- update ---

I think the most feasible solution would be either:

1) merge two views (one that selects the latest promoted articles with an offset of 6 and one that selects the latest regular articles together with some sort of union functionality and then limit it to 12
2) remove duplicates: so create a view that displays the latest 12 articles of any type, but which has been filtered in order to remove duplicates between the articles that are displayed in block 1

Haven't found a solution on either though...

1
  • I am still looking for a solution on this...
    – grrrbytes
    Commented May 30, 2012 at 10:52

2 Answers 2

0

Build a single view with two displays. One for the first block, which will list the latest 6 promoted articles, and one for the second block which will list the latest 18 articles (promoted or not). Then in a custom module, implement hook_views_pre_render() to filter out the six first promoted articles from the second block and limit them to 12.

function MODULE_views_pre_render(&$view) {
  if ($view->name === 'VIEWNAME' && $view->current_display === 'block_2') {
    $count = 0;
    $promoted_count = 0;
    foreach ($view->result as $key => $value) {
      If ($promoted_count < 6 && $value->node_promoted) {
        $promoted_count++;
        unset($view->result[$key]);
      }
      else {
        if ($count < 12) {
          $count++;
        }
        else {
          unset($view->result[$key]);
        }
      }
    }
  }
}

Note: $value->node_promoted is dependent on the view display mode being fields and having the Promoted field. node_promoted may not be the correct property name.

0

Here is one approach.

Make a view that lists all articles, no filter on "promoted to front page"

Now sort first by "promoted to front page", descending (so promoted articles come first), then by post date (or what ever else you want)

Now limit it to 6 items.

Clone the view (or block display)

Change the limit setting so there is an offset of 6 (if you cloned the block display) make sure you save the new setting only for the new block (an override)

1
  • Isn't the problem with this approach that it does not meet this requirement: when an article shifts out of bock 1 it should shift towards block 2, **assuming it is not older than the 12th article in this block**. I mean, even promoted to frontpage articles that are a year old would get preference over a regular article that has been posted today, right?
    – grrrbytes
    Commented Apr 29, 2012 at 8:21

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.