Created
May 15, 2012 18:48
-
-
Save robballou/2704120 to your computer and use it in GitHub Desktop.
Custom Module block code
This file contains hidden or 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
<?php | |
// hook_block_info | |
/** | |
* Our block specific code | |
*/ | |
function custom_module_block_view($delta = '') { | |
if ($delta == ''){ | |
// current node | |
$node = node_load(arg(1)); | |
// get something related from our database | |
$query = db_select('some_table'); | |
$query | |
->fields('some_table', array('sid')) | |
->condition('some_table.nid', $node->nid, '='); | |
$related_id = $query->execute()->fetchAssoc(); | |
// load our view and pass it | |
$view = views_get_view('machine_name_for_view'); | |
$view->init(); | |
// you can change this to be the name of the display you want | |
// to use | |
$view->set_display('block'); | |
$view->set_arguments(array($related_id['sid'])); | |
return $view->render(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment