Created
August 31, 2011 20:07
-
-
Save twohlix/1184570 to your computer and use it in GitHub Desktop.
Get Nids from Views Results into another View passively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////// | |
// Get Nids from Views Results into another View passively | |
// | |
// Problem with below code is caching | |
// 'featured_nids' may not get updated before views_pre_view | |
// this will lead to an issue where the args set on 'blogs' | |
// will always be lagging behind by 1 cache clear. | |
//hook_views_pre_view | |
function blog_views_pre_view(&$view, &$display_id, &$args){ | |
//dpm($view); dpm($display_id); dpm($args); | |
if($view->name == 'blogs'){ | |
//get some nids to not show in the blog block | |
$nids = variable_get('featured_nids', array()); | |
//append them as args | |
$args = array_merge($args, $nids); | |
} | |
} | |
//hook_views_pre_render | |
function blog_views_pre_render(&$view){ | |
//if we're in this hook, something changed | |
if($view->name == 'home_page_feature_rotator'){ | |
//grab nids | |
$view_cont = $view->result; | |
$to_set = array(); | |
foreach( $view_cont as $res ){ | |
$to_set[] = $res->nid; | |
} | |
variable_set('featured_nids', $to_set); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment