Drupal API

如何得到drupal的其他相关文章 db_query和node_load_multiple

日期:2015-03-25 阅读:1910

dmandwp系统 - wordpress系统和DM系统区块建站>>

代码如下:

原理是,相同的type,但不是本id.

<?php
$nids = db_query("SELECT n.nid FROM {node} n WHERE n.status = 1 AND n.type = :type AND n.nid <> :nid ORDER BY RAND() LIMIT 0,4", array(':type' => 'portfolio', ':nid' => $node->nid))->fetchCol();

$nodes = node_load_multiple($nids);
?>
<?php if (!empty($nodes)): ?>

  <!-- Portfolio Content -->

  <!-- Related Project -->
  <div class="sixteen columns">
    <h3 class="page_headline"><?php print t('Related Projects'); ?></h3>
  </div><!-- End Related Project -->

  <?php foreach ($nodes as $node) : ?>
    <!-- 1/4 Column -->
    <div class="four columns portfolio-item architecture real-estate">
      <?php $field_image = field_get_items('node', $node, 'field_image'); ?>
      <?php if (!empty($field_image)) : ?>
        <div class="item-img"><a href="<?php print url('node/' . $node->nid); ?>"><?php print theme('image_style', array('style_name' => 'portfolio_view', 'path' => $field_image[0]['uri'])); ?><div class="overlay link"></div></a></div>
      <?php endif; ?>
      <div class="portfolio-item-meta">
        <h4><?php print l($node->title, 'node/' . $node->nid); ?></h4>

        <?php
        $body = field_get_items('node', $node, 'body');
        if (!empty($body)) {
          print custom_trim_text(array('max_length' => 120), $body[0]['value']); // custom_trim_text 是一个自定义函数
        }
        ?>
      </div>
    </div>
  <?php endforeach; ?>

<?php endif; ?>

 

 

<<点击返回

Drupal7视频教程 Drupal7主题 Drupal7最新文档 Drupal7推荐文档
  • 暂无内容!
  • 暂无内容!