theme_links

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

includes/theme.inc, строка 1143

Версии
5 – 6
theme_links($links, $attributes = array('class' => 'links'))

Возвращает темизированный набор ссылок.

Параметры

$links Ассоциативный массив ссылок, которые нужно темизировать.

$attributes Ассоциативный массив HTML аттрибутов.

Возвращаемое значение

Строка, содержащая список ссылок.

Связанные темы

▾ 8 функции вызывают theme_links()

chameleon_comment in themes/chameleon/chameleon.theme
chameleon_node in themes/chameleon/chameleon.theme
chameleon_page in themes/chameleon/chameleon.theme
locale_block in modules/locale/locale.module
Реализация hook_block(). Отображает переключатель языков. Ссылки могут быть предоставлены другими модулями.
template_preprocess_comment in modules/comment/comment.module
Process variables for comment.tpl.php. See alsocomment.tpl.php
template_preprocess_node in includes/theme.inc
Обрабатывает переменные для node.tpl.php
template_preprocess_poll_results in modules/poll/poll.module
Preprocess the poll_results theme hook.
theme_update_version in modules/update/update.report.inc
Темизирует отображение версии проекта.

Код

<?php
function theme_links($links, $attributes = array('class' => 'links')) {
  global $language;
  $output = '';

  if (count($links) > 0) {
    $output = '<ul'. drupal_attributes($attributes) .'>';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $key => $link) {
      $class = $key;

      // Add first, last and active classes to the list of links to help out themers.
      if ($i == 1) {
        $class .= ' first';
      }
      if ($i == $num_links) {
        $class .= ' last';
      }
      if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
          && (empty($link['language']) || $link['language']->language == $language->language)) {
        $class .= ' active';
      }
      $output .= '<li'. drupal_attributes(array('class' => $class)) .'>';

      if (isset($link['href'])) {
        // Pass in $link as $options, they share the same keys.
        $output .= l($link['title'], $link['href'], $link);
      }
      else if (!empty($link['title'])) {
        // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (empty($link['html'])) {
          $link['title'] = check_plain($link['title']);
        }
        $span_attributes = '';
        if (isset($link['attributes'])) {
          $span_attributes = drupal_attributes($link['attributes']);
        }
        $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
      }

      $i++;
      $output .= "</li>\n";
    }

    $output .= '</ul>';
  }

  return $output;
}
?>

Пользовательские комментарии

Простой пример массива $links:

<?php 
$linklist = array(
  'item1' => array( 'title' => '1st Item', 'href' => 'one' ),
  'item2' => array( 'title' => '2nd Item', 'href' => 'two' ),
  'item3' => array( 'title' => '3rd Item'),
             array( 'title' => '4th Item', 'href' => 'four' ),
  'item5' => '',
  'item6' => array( 'title' => '6th Item', 'href' => 'six' )
);
?>

Полный набор параметров:

<?php
$links = array(
  'digg' => array(
    'title' => '<img src="images/diggit.gif" alt="Digg It" />',
    'href'  => 'http://digg.com/submit',
    'query' => 'phase=2&url=http://mysite.example.com',
    'attributes' => array('target' => '_blank'),
    'fragment' => 'sillyexample',
    'html' => TRUE
  )
);
?>

Много подробностей здесь: http://www.group42.ca/theming_101_the_theme_links_function

Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему