Drupal 6

Прописываем редиректы в .htaccess


# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
# RewriteBase /drupal
#
# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
# RewriteBase /

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Не работают jQuery слайдеры

Если вы выводите блок через views_embed_view(), то у вас не будут работать карусли/слайдеры и т.п., т.к. через views_embed_view() не подключаются все необходимые js и другие файлы модуля - их нужно подключать вручную, поэтому, я считаю что проще делать это следующим образом → создать регион и через админку вывести блок в этот регион.

Использование javascript inline в друпал функции l()

print l('Some link name', '', array('attributes' => array('onclick' => 'myfunction()')));

Убираем ненужные филдсеты hook_form_alter

Часто у всех возникает вопрос - как убрать лишние филдсеты при создании ноды node/add/page. Делается это все очень просто, для этого нужно создать свой модуль и использовать в нём hook_form_alter():

Создаем mymodule.info файл.


name = Name of our module
description = Desription about our module
core = 6.x
version = 6.x - 1.0

Создаем mymodule.module файл.

function mymodule_form_alter(&$form, $form_state, $form_id) {
  drupal_set_message($form_id); // Узнаем ID формы
  switch($form_id) {
    case 'page_node_form':

Вывод списка нод, которые начинаются на определенную букву

$result = db_query_range("SELECT title, nid FROM {node} WHERE title LIKE 'A%%' LIMIT %d, %d", 0, 50);
while {$node = db_fetch_object($result)) {
    $nodes[] = l($node->title, 'node/'.$node->nid);
}
foreach ($node as $nodes) {
   print $nodes.'<br />';
}

Код выше выведет нам список всех нод, которые начинаются на букву А, по поводу вопросительных знаков - это так называемые Wildcards.

Если нужно вывести список нод определенного термина таксономии, то вам сюда: http://webcoder.kz/vyvod-spiska-nod-opredelennogo-termina-taksonomii

Вывод списка нод определенного термина таксономии

    $result = db_query("SELECT {node}.title, {node}.nid FROM {node} INNER JOIN {term_node} ON {node}.nid = {term_node}.nid WHERE {term_node}.tid = %d ORDER by {node}.title ASC LIMIT %d, %d", 148, 0, 50);
    while ($node = db_fetch_object($result)) {
        $nodes[] = l($node->title, 'node/'.$node->nid);
    }
    foreach ($nodes as $list) {
        print $list.'<br />';
    }

The _custom_breadcrumbs_get_breadcrumb() function called token replacement with an array rather than a string for $text

custom_breadcrumbs 6.x-2.0-rc1 version

Замените в файле custom_breadcrumbs.module с 370 по 383 на следующий код:

  // Token replacement for titles and paths
  if (module_exists('token')) {
    // Do token replacement.
    $types = custom_breadcrumbs_token_types($objs);
    #PB:20111102 foreach on titles and paths because il token_replace_multiple require a string
   foreach($titles as $key => $value) {
        $titles[$key] = token_replace_multiple($value, $types);
    }
    foreach($paths as $key => $value) {

php strtolower() not working in drupal

Если у вас не работает в друпале стандартная PHP функция strtolower($string), то заместо неё нужно использовать родную друпаловску функция -> drupal_strtolower($text)

Пример

drupal_strtolower($text);
$text = 'Hello, Grand Mother!';
print $text; // would print hello, grand mother!

Счетчик посетителей (Сниппет)

/**
 * Compute the counters.
 */

if (!($counter_since = variable_get('mycounter_since', 0))) {
  $page_hits = 1;
  $unique_visits = 1;
  $counter_since = time();
  $_SESSION['mycounter'] = TRUE;
  variable_set('mycounter_page_hits', 1);
  variable_set('mycounter_unique_visits', 1);
  variable_set('mycounter_since', $counter_since);
}
else {
  $page_hits = (int)variable_get('mycounter_page_hits', 0);
  $unique_visits = (int)variable_get('mycounter_unique_visits', 0);
  if (!isset($_SESSION['mycounter'])) {
    $_SESSION['mycounter'] = TRUE;
    $unique_visits++;

Контактная форма в ноде

Открываете ваш шаблон ноды, например node-16.tpl.php (Как заставить работать такого вида шаблон - я писал уже тут).

Далее в шаблон вашей ноды, в которую вы хотите вставить контакнтую форму вставляете следующий код:

  require_once drupal_get_path('module', 'contact') .'/contact.pages.inc';
 
  //no need to maintain two version of node.tpl.php
  include "node.tpl.php";

function local_contact_page(){
    $form = contact_mail_page();
    // override default values here if you want

Syndicate content