Creating a nice tabbed output using Views3 in Drupal 7 http://www.appliedtrust.com/blog/2012/04/creating-a-nice-tabbed-output-using-views3-in-drupal-7

Public
</> CopyGet raw version
php
  1. // get the view, ‘resources’ here is the machine name of your view.
  2. $view = views_get_view('resources');
  3.  
  4. // add a container to hold your tabs
  5. $tabs = '<div id="resource-tabs"><ul>';
  6. $content = '';
  7.  
  8. $num_views = count($view->display);
  9. $i=1;
  10. foreach ($view->display as $name => $v) {
  11. // we don't want the default block included here
  12. if ($name != 'default') {
  13.  
  14. // this will allow us to add a class to the very last tab for theming purposes
  15. $last = ($num_views == $i) ? " class='last' " : "";
  16. // build the tab
  17. $tabs .= "<li><a href='#tabs-$name'$last>$v->display_title</a></li>";
  18.  
  19. // get the content for this view.
  20. $embed_view = views_embed_view('resources', $name);
  21. $content .= "<div id='tabs-$name'>" . $embed_view . "</div>";
  22. }
  23. $i++;
  24. }
  25.  
  26. $tabs .= '</ul>';
  27. $tabs .= $content;
  28. $tabs .= '</div>';
  29.  
  30. $variables['resource_tabs'] = $tabs;
  31.  
  32. // and add the js to handle these tabs
  33. drupal_add_library('system', 'ui.tabs');
  34. drupal_add_js('jQuery(document).ready(function(){jQuery("#resource-tabs").tabs();});', 'inline');