Generating Views Block to list Taxonomy Terms of nodes curently visible in a Views Page I have a Views Page which lists nodes of the content type, Article. This page also contains pagination since I configured it to display no more than 6 articles per page.

So for example, if I have 10 articles, 6 of them would be displayed on page 1 and the remaining 4 would be on page 2. In addition, Article has a term reference field called Tags. 

I was wondering if it's possible to have a Views block I can attach to my original View I mentioned earlier (a list of Article content type) that lists Tags belonging only Articles currently visible on the original View on one of the paginated pages.

Going again with my example, I want this Views block to display Tags from the 6 Articles when I'm on page 1. Likewise, I want this block to display Tags from the remaining 4 Articles when I'm on page 2.

Here's a little graphic of what I'm trying to do.
http://i.imgur.com/7rPsLaz.png

Also, I'm not sure if this info is relevant but I plan to use the Context module to attach this Views Block to the Views page.

I was thinking along the lines of Contextual Filters but I'm not quite sure what arguments I would use.

Any help is appreciated.
Offhand i'm not sure how Context will help you do this ... off the top of my head this solution came to mind.


In your 1st view make the Tag field a hidden field the view so the View knows about it.
Use hook_views_pre_render to loop through the results (and maybe respect page offset and # of items per page -- you can get that from the $view object) and grab your view field Tag values and store them into an array.
Still in hook_views_pre_render you can set $view-&gt;attachment_after = $some_string; where $some_string is like the list of your Tags.


In code it will look something like this:

function MYMODULE_views_pre_render(&amp;$view) {
  if ($view-&gt;current_display == 'VIEW_ID') {
    $tags_on_page = array();
    // $_GET['page'] has page number.
    // $views-&gt;items_per_page has items per page count.

    $page_offset = intval($_GET['page']);
    // this is somewhat wasteful, but easier than a loop at the moment.
    $paged_results = array_chunk($view-&gt;result, $view-&gt;items_per_page, TRUE);

    // Build up the Tag list for X page of the results.
    foreach ($paged_results[$page_offset] as $i =&gt; $result) {
      $tags_on_page[] = $result-&gt;value; // save the taxonomy term name to the tags list.
    }

    // Take our tags and build a block of HTML to embed after the view.
    // Alternatively, maybe take these tag values and pass them as parameters
    // to a new view we attach after programmatically -- thats more work.

    // if you know the url prefix you've given these taxonomy terms use it here, or use something like entity_uri().
    $num_tags = count($tags_on_page);
    if ($num_tags) {
      for ($i=0;$i&lt;$num_tags; $i++) {
        $term = $tags_on_page[$i];
        $tags_on_page[$i] = l($term, '/URL/ALIAS/BASE/PATH/TO/TERM' . $term);
        // or, ... $term may have a path value already ... I cant remember :).
        // $term = taxonomy_get_term_by_name($tags_on_page[$i]);
        // $term_path = entity_uri('taxonomy_term', $term[0]);
        // $tags_on_page[$i] = l($term[0]-&gt;name, $term_path);
      }
      $links = implode('&lt;br&gt;', $tags_on_page);
      $view-&gt;attachment_after = '&lt;div class="myBlockAfterView"&gt;&lt;h3&gt;Related Tags&lt;/h3&gt;' . $links . '&lt;/div&gt;';
    }

  }
}