0

I have three content type 1) Slideshow 2) Slides 3) Advertisement

While creating slideshow we can assign slides to slideshow with nodereference field. We have created a views for slideshow on the view page of slideshow we are displaying all the slides one by one and there are two links next and previous. Now I want to add a single Advertisement at the end of this slideshow view.

I tried hook_views_api() and hook_views_query_alter(). Content type slides and advertisements have different fields.

1 Answer 1

1

slides are usually images or maybe node bodies (html). It doesnt really matter that advertisments have different fields. I had some code in Drupal 6 you could adapt to D7 or your needs, look into hook_views_pre_render() ...

You simply want to load your advertisement node(s) before the view is rendered and add them to the end of the slideshow ... see below.

//d6 example
function MYMODULE_views_pre_render(&$view) {

  if ($view->name == 'your_view' &&
    $view->current_display == 'slideshow_xyz') {
    // Insert something to the end of the view results.
    // For example another "node" or advertisement.
    $some_node = node_load(array('nid' => 456));
    // make a fake view row item with your advertisement.
    // you should create all fields used in "slides" from your
    // advertisement node data.
    $advertisement_item = new stdClass();
    // add your advertisement fields as fields being used by the Slide view.
    $advertisement_item->a_field_views_is_using = $some_node->advertisement_field_1;
    //  ... add all other view row items you are using ....
    // make this advertisement "row" in the results appending to the view results for slides.
    array_push($view->result, $advertisement_item);
  }
}
4
  • Can you please let me know how can I implement this in Druapl 7? Jun 26, 2012 at 5:03
  • i think the exact same approach will work -- the function takes the same arguments in D6/D7.
    – tenken
    Jun 26, 2012 at 5:25
  • I have a problem with next and previous button from query it will fetch always -1 records and we are adding 1 extra to the array so that is why I cannot navigate from the next button but from url it is working fine. thanks for your suggestion. Jun 26, 2012 at 7:10
  • Can you please let me know how can I change pager array? Jun 26, 2012 at 9:32

Your Answer

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

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