【发布时间】:2023-03-04 16:30:01
【问题描述】:
我正在尝试在节点内插入一个块。问题是我希望它在第 X 段之后自动出现,最好是在第一段之后。
AdSense Injector 模块 (http://drupal.org/project/adsense_injector) 非常有用,但不是很灵活,因为您只能插入一个代码。由于我打算在不同的情况下插入不同的块,所以我想在第一段之后插入一个区域。
有一个教程 (www.werockyourweb.com/drupal-insert-adsense-ads-into-middle-of-content) 似乎不适用于 Drupal 7。
这是视觉解释:
<h1>Title</h1>
<p>Some text here</p>
<div>BLOCK INSIDE OF THE NEW REGION</div>
<p>Some text here</p>
有人可以提供一些指导吗?
编辑:
这是我正在使用的代码。
块代码:
<h2>Is this working?</h2>
.info 文件:
regions[testing] = 'Testing'
模板.php
function THEMENAME_preprocess_node(&$variables) {
//load your adblock
$testing = block_load('block', '1');
$output .= drupal_render(_block_get_renderable_array(_block_render_blocks(array($testing))));
$variables['ad'] = $output;
}
Node.tpl.php
<?php
$array = explode("</p>", $body[0]['value']);
$array[1] = $ad. $array[1];
$content['body'] = implode("</p>", $array);
print render($content['body']);
?>
【问题讨论】:
-
您是否使用教程中标记为在 drupal 7 中工作的代码?如果是这样,当你使用它时会发生什么? “不起作用”对于故障排除不是很有帮助。
-
解析错误:语法错误,第 31 行的 ...template.php 中出现意外 $end。我可能将其余代码插入错误。