I wanted to make nice tabbed sections that would hold lots of Views content for news sites, simplifying navigation, and allowing the visitor to hang out on the front page for as long as they needed to.

You can use this code in a number of different places. For example, if you want to place a display like this in the footer of every page, you might put it into the footer section in the site settings. Perhaps into a node, while selecting an input format of php, or a block! You can put this anywhere you can put php.

Here's the basics of the code that I ended up with, and I hope you find it helpful. There is at least 1 variable that you will need to change in this first example. 'name-of-my-view' needs to be swapped out for the name of the view you want to use for your site. Ideally, you might swap out '$my-view-php-code-output' for something more informative and relevant to your view. Basically, that variable is storing the php output of your view, so name it so that that makes sense when you look at it again in a year.

     //this is to handle an error generated in older versions of views
  $view_args = array();  
     //this is where I declare a variable that is holding the view I want to call on
  $my-view-php-code-output = views_build_view('embed', views_get_view('name_of_my_view'), $view_args, true,   $limit);
    //This is the tabs code where I insert my new variable
  $tabs .= theme('tabs_tab_page', t('My Tab Title'), t($my-view-php-code-output));
  $output = theme('tabs_tabset', 'example', $tabs);
  print $output; 

You can declare as many view holding variables as you need, and then print as many tabs as you would like. For example, here's the same thing, but with two views, two tabs. Again, you should change out 'name-of-view-1' to a name that matches a view on your site.

     //this is to handle an error generated in older versions of views
  $view_args = array();  
     //this is where I declare a variable that is holding the view I want to call on
  $my-first-view = views_build_view('embed', views_get_view('name_of_view_1'), $view_args, true,   $limit);
  $my-second-view = views_build_view('embed', views_get_view('name_of_view_2'), $view_args, true,   $limit);
    //This is the tabs code where I insert my new variable
  $tabs .= theme('tabs_tab_page', t('My Tab Title'), t($my-first-view));
  $tabs .= theme('tabs_tab_page', t('My Tab Title'), t($my-second-view));
  $output = theme('tabs_tabset', 'example', $tabs);
  print $output; 

This took awhile to track down, but in the end it is so simple that I hope many others will find easy ways to improve the usability of their content heavy sites.

Comments

josoroma’s picture

Thanks to:
http://drupal.org/node/139668
http://cvs.drupal.org/viewcvs/drupal/contributions/modules/jstools/tabs/...


  $module = 'views';
  $delta = 'latest_videos';
  $block = (object) module_invoke($module, 'block', 'view', $delta);
  $block->module = $module;
  $block->delta = $delta;
  $tab_B = theme('block', $block);

  $form = array();

  $form['example1'] = array(
    '#type' => 'tabset',
  );
  $form['example1']['tab1'] = array(
    '#type' => 'tabpage',
    '#title' => t('One'),
    '#content' => drupal_get_form('user_login_block'),
  );
  $form['example1']['tab2'] = array(
    '#type' => 'tabpage',
    '#title' => t('Two'),
    '#content' => $tab_B,
  );
  $form['example1']['tab3'] = array(
    '#type' => 'tabpage',
    '#title' => t('Three'),
    '#content' => t('Third tab content.'),
  );

  return tabs_render($form);

josoroma’s picture

[view:frontpage=3]


	/* ---------------------------------------------------------- */

	$module = 'views';
	$delta = 'calendar';

	$block = (object) module_invoke($module, 'block', 'view', $delta);
	$block->module = $module;
	$block->delta = $delta;

	$tab_A = theme('block', $block);

	/* ---------------------------------------------------------- */

	$module = 'views';
	$delta = 'latest_videos';

	$block = (object) module_invoke($module, 'block', 'view', $delta);
	$block->module = $module;
	$block->delta = $delta;

	$tab_B = theme('block', $block);

	/* ---------------------------------------------------------- */

	$form = array();

	$form['hpTabs'] = array(
		'#type' => 'tabset',
	);

	$form['hpTabs']['tab1'] = array(
		'#type' => 'tabpage',
		'#title' => t('Calendar'),
		'#content' => $tab_A,
	);

	$form['hpTabs']['tab2'] = array(
		'#type' => 'tabpage',
		'#title' => t('Video'),
		'#content' => $tab_B,
	);

	$form['hpTabs']['tab3'] = array(
		'#type' => 'tabpage',
		'#title' => t('Three'),
		'#content' => t('Third tab content.'),
	);

	return tabs_render($form);

	/* ---------------------------------------------------------- */

josoroma’s picture

Using:
http://drupal.org/project/insert_view

    /* ---------------------------------------------------------- */

    $module = 'views';
    $delta = 'calendar';

    $block = (object) module_invoke($module, 'block', 'view', $delta);
    $block->module = $module;
    $block->delta = $delta;

    $tab_A = theme('block', $block);

    /* ---------------------------------------------------------- */

    $module = 'views';
    $delta = 'latest_videos';

    $block = (object) module_invoke($module, 'block', 'view', $delta);
    $block->module = $module;
    $block->delta = $delta;

    $tab_B = theme('block', $block);

    /* ---------------------------------------------------------- */

    $form = array();

    $form['hpTabs'] = array(
        '#type' => 'tabset',
    );

    $form['hpTabs']['tab1'] = array(
        '#type' => 'tabpage',
        '#title' => t('Calendar'),
        '#content' => $tab_A,
    );

    $form['hpTabs']['tab2'] = array(
        '#type' => 'tabpage',
        '#title' => t('Video'),
        '#content' => $tab_B,
    );

    $form['hpTabs']['tab3'] = array(
        '#type' => 'tabpage',
        '#title' => t('Three'),
        '#content' => t('Third tab content.'),
    );

    return tabs_render($form);

    /* ---------------------------------------------------------- */

[view:frontpage=3]

Observer123’s picture

is there the same code necesery?