hiweed 是不是考虑加一个 image 导航的 block

下面的图片导航来自 http://willwyatt.com/node/1568 ,我在 drupal 4.7.3 上试验成功。

  1. 准备两张图片提示用户已经到了第一张图片和最后一张图片。:
    * placeholder_first_photo.gif
    * placeholder_last_photo.gif
  2. 建立一个 'PHP code' 的 block:

    <?php
    if (arg(0) == 'node' && is_numeric(arg(1))) {
    $nid = arg(1);
    $node = node_load(array('nid' => $nid));
    $previous=0;
    $next=0;
    $tmp_prev=-1;
    $terms = taxonomy_node_get_terms_by_vocabulary($node->nid, _image_gallery_get_vid());
    if ($terms) {
    $term = array_pop($terms);
    $res = db_query("SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d ORDER BY n.sticky DESC, n.created DESC", $term->tid);
    $tot_num = db_num_rows($res);
    for($i=0; $i < $tot_num; $i++) {
    $nidvalue=db_result($res,$i);
    if($previous!=0 && $next==0) {
    $next=$nidvalue;
    }
    if($nidvalue == intval($node->nid)) {
    $previous=$tmp_prev;
    }
    $tmp_prev=$nidvalue;
    }
    $prev_node = node_load(array('nid' => $previous));
    $next_node = node_load(array('nid' => $next));
    $prev_th = ($previous == -1) ? '' : l(image_display($prev_node, 'thumbnail', array('width' => '120', 'height' => '120')),'node/'.$prev_node->nid, array(), null, null, FALSE, TRUE);
    $next_th = ($next == 0) ? '' : l(image_display($next_node, 'thumbnail', array('width' => '120', 'height' => '120')),'node/'.$next_node->nid, array(), null, null, FALSE, TRUE);
    $output = '';
    $output .= '';
    $output .= '';
    $output .= '' . $prev_th . '' . (($previous == -1) ? ' ' : l('Previous','node/'.$prev_node->nid, array(), null, null, FALSE, FALSE)) . '' . $next_th . '' . (($next == -1) ? ' ' : l('Next','node/'.$next_node->nid, array(), null, null, FALSE, FALSE)) . '';
    $output .= '' . $tot_num . ' photos in this album.';
    $output .= '';
    $output .= '';
    print $output;
    }
    }
    ?>
  3. 上面关于两个 placeholder 图片的地址要根据自己实际情况修改。
  4. 为了让这个 block 仅出现在图片页面,选择 'Show if the following PHP code returns TRUE (PHP-mode, experts only).',然后用下面的代码控制:

    <?php
    $match = FALSE;
    $types = array('image' => 1);
    if (arg(0) == 'node' && is_numeric(arg(1))) {
    $nid = arg(1);
    $node = node_load(array('nid' => $nid));
    $type = $node->type;
    if (isset($types[$type])) {
    $match = TRUE;
    }
    }
    return $match;
    ?>
  5. 保存 block 就可以检查了。
  6. 也可以稍微做一些 style:
    .image_browser td {
    padding: 5px 0 0 5px;
    }