Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have a view that output the content nodes as grid. (instigram style). How to insert an advertisement block in a random location within the views list.

Node Node . . Advertisement . . Node Node

share|improve this question
    
I think you must use the views hooks after generating result. then count the result's rows and select the random position between rows , finally you must load your advertisement block and insert it into the #markup nodes in the selected rows. For this issue, module programming is needed buy maybe the other friends can help you to do it only with views definition. –  Mehrdad201 Feb 11 at 7:37
add comment

1 Answer 1

up vote 5 down vote accepted

You can override the format specific template like views-view-unformatted.tpl.php (you can find the right file based on your requirement) and then use some custom code like

  <?php if (($id % 2) == 0): ?>
    Do what-ever you want to do here. 
  <?php endif; ?>

This module hosted on github https://github.com/pedroposada/custom_views_nthrow seems to do the same more modularly.

Instructions : http://www.pedroposada.com/blog/insert-whatever-every-nth-row-views.html-0

share|improve this answer
1  
Thx !! Just what i needed !! i ended overriding "views-view-unformatted.tpl.php" and inserting the ad block in a random location wihin the loop. –  Barjas Feb 11 at 8:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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