function theme_name_preprocess_node(&$vars, $hook) {
// don't load region in teaser view
if ($hook == 'node' && !$vars['teaser']) {
$vars['incontent'] = theme('blocks', 'incontent');
}
}
$arr = explode ("</p>", $content); // center content ads
$arr[2] = $incontent . $arr[2];
$content = implode("</p>", $arr);

I found the above code which displays an ad block in the middle of content in drupal 6. I want to do this in drupal 7 how do i make this code work for me.

Comments

schnelle02’s picture

it takes slightly different syntax for D6 or D7 to hardcode a block with PHP in content or anywhere for that matter.

D6:

$block = module_invoke('search', 'block', 'view', 'form');
print $block['content'];

D7:

$block = module_invoke('search', 'block_view', 'form');
print render($block);

This prints the search form anywhere, simply change the "search" to any MODULENAME and change "form" to any BLOCK_ID. you can find these at the end of the URL while you are in Structure ---> Blocks ---> Configure (desired block to print).

The end will look like this in D6: modulename/block_id
In D7: modulename/block_id/configure (just ignore the configure on the end)

cxc891’s picture

Tried render($block); on D7.35 with php 5.6 it results in some php warnings regarding to common.inc, did some research and found print render($block['content']);might be a better way to go from now on.

manishdrupaldev’s picture

you can try this:

    $block = module_invoke('addthis', 'block_view', 'addthis_block');
    (addthis   = Module name, block_view  = Type of view, addthis_block = Block Delta)
    print render($block['content']);

-----OR------

    $blockObject = block_load('views', 'block-name');
    $block = _block_get_renderable_array(_block_render_blocks(array($blockObject)));
    $output = drupal_render($block);
    print $output;