Для размещения рекламных материалов либо просто текста между строк в табличном виде в template.php своей темы добавляете:
function ИМЯТЕМЫ_preprocess_views_view_table(&$vars) {
$view = $vars['view'];
if ($view->name == 'myview') { // если для всех видов, то это условие убрать
$vars['ad'] = array(
5 => 'реклама 1', // вывод рекламы после 5-й строки
10 => 'реклама 2', // после 10-й
);
}
}
$view = $vars['view'];
if ($view->name == 'myview') { // если для всех видов, то это условие убрать
$vars['ad'] = array(
5 => 'реклама 1', // вывод рекламы после 5-й строки
10 => 'реклама 2', // после 10-й
);
}
}
Реклама не будет показываться, если после неё нет другой строки.
В папке с темой создаем шаблон views-view-table.tpl.php с кодом:
<?php
// $Id: views-view-table.tpl.php,v 1.8 2009/01/28 00:43:43 merlinofchaos Exp $
/**
* @file views-view-table.tpl.php
* Template to display a view as a table.
*
* - $title : The title of this group of rows. May be empty.
* - $header: An array of header labels keyed by field id.
* - $fields: An array of CSS IDs to use for each field id.
* - $class: A class or classes to apply to the table, based on settings.
* - $row_classes: An array of classes to apply to each row, indexed by row
* number. This matches the index in $rows.
* - $rows: An array of row items. Each row is an array of content.
* $rows are keyed by row number, fields within rows are keyed by field ID.
* @ingroup views_templates
*/
$n = 0;
$total = count($rows);
?>
<table class="<?php print $class; ?>">
<?php if (!empty($title)) : ?>
<caption><?php print $title; ?></caption>
<?php endif; ?>
<thead>
<tr>
<?php foreach ($header as $field => $label): ?>
<th class="views-field views-field-<?php print $fields[$field]; ?>">
<?php print $label; ?>
</th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ($rows as $count => $row): ?>
<?php if (isset($ad[$count])): ?>
<tr class="<?php print implode(' ', $row_classes[$n]);?>"><td <? print 'colspan="'. count($row).'"'; ?>><?php print $ad[$count]; ?></td></tr>
<?php
$row_classes[$total] = array(($total % 2 == 0) ? 'odd' : 'even', 'views-row-last');
$row_classes[$total-1] = array((($total-1) % 2 == 0) ? 'odd' : 'even');
$total++;
$n++;
?>
<?php endif; ?>
<tr class="<?php print implode(' ', $row_classes[$n]); ?>">
<?php foreach ($row as $field => $content): ?>
<td class="views-field views-field-<?php print $fields[$field]; ?>">
<?php print $content; ?>
</td>
<?php endforeach; ?>
</tr>
<?php $n++; ?>
<?php endforeach; ?>
</tbody>
</table>
// $Id: views-view-table.tpl.php,v 1.8 2009/01/28 00:43:43 merlinofchaos Exp $
/**
* @file views-view-table.tpl.php
* Template to display a view as a table.
*
* - $title : The title of this group of rows. May be empty.
* - $header: An array of header labels keyed by field id.
* - $fields: An array of CSS IDs to use for each field id.
* - $class: A class or classes to apply to the table, based on settings.
* - $row_classes: An array of classes to apply to each row, indexed by row
* number. This matches the index in $rows.
* - $rows: An array of row items. Each row is an array of content.
* $rows are keyed by row number, fields within rows are keyed by field ID.
* @ingroup views_templates
*/
$n = 0;
$total = count($rows);
?>
<table class="<?php print $class; ?>">
<?php if (!empty($title)) : ?>
<caption><?php print $title; ?></caption>
<?php endif; ?>
<thead>
<tr>
<?php foreach ($header as $field => $label): ?>
<th class="views-field views-field-<?php print $fields[$field]; ?>">
<?php print $label; ?>
</th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ($rows as $count => $row): ?>
<?php if (isset($ad[$count])): ?>
<tr class="<?php print implode(' ', $row_classes[$n]);?>"><td <? print 'colspan="'. count($row).'"'; ?>><?php print $ad[$count]; ?></td></tr>
<?php
$row_classes[$total] = array(($total % 2 == 0) ? 'odd' : 'even', 'views-row-last');
$row_classes[$total-1] = array((($total-1) % 2 == 0) ? 'odd' : 'even');
$total++;
$n++;
?>
<?php endif; ?>
<tr class="<?php print implode(' ', $row_classes[$n]); ?>">
<?php foreach ($row as $field => $content): ?>
<td class="views-field views-field-<?php print $fields[$field]; ?>">
<?php print $content; ?>
</td>
<?php endforeach; ?>
</tr>
<?php $n++; ?>
<?php endforeach; ?>
</tbody>
</table>





Комментарии (2)
Полезное решение.
Спасибо
Думаю это очень полезно для Ads и для показа Google AdSense.