gpt4 book ai didi

Drupal 7,不确定如何从查询数据中正确主题化我的输出

转载 作者:行者123 更新时间:2023-12-01 15:33:20 24 4
gpt4 key购买 nike

我一直在使用 View 来选择性地返回节点,但现在我想返回我的节点并将分类术语用作组标题。无论如何,我看不到让 View 为我执行此操作,然后在一个页面上创建多个 View 。

所以我想我会选择一个模块。我已经编写了 SQL 来返回正确的节点,但我不知道如何正确地将它们发送到主题引擎。我想要一些关于如何去做的建议,我的教程书中有一些构建列表的例子,如下所示。

foreach ($result as $row2) {
$items[] = l($row2->title,'node/'.$row2->nid.'/edit');
}
return array('#markup' => theme('item_list',array('items' => $items)));

现在我想以 Teaser 模式返回我的节点附加图像文件,以及节点的标题,另外(我不想超越自己)我可能还想要在标题上附加几个附加节点字段。应该很容易吧?我根本搞不定。

我通过使用我确定是一种看起来有点像这样的非drupal方法来解决它(有点),问题是我无法让我的输出与ColorBox模块一起使用,所以我在想如果我能得到官方的 Teaser 节点数据,它可能会更好,而且我会感觉更好,因为我知道我正在以一种 Drupaly 的方式做事:)
foreach ($result as $row2) {
$items .= '<img title="'.$row2->title.' '.$row2->fielddata.'" alt="'.$row2->title.'" src="http://localhost/theme/sites/default/files/styles/thumbnail/public/field/image/'.$row2->filename .'"></a>';
$items .= '</div></div></div></div>';
}
return array('#markup' => $items);

非常感谢您花时间帮助我并提前感谢。

最佳答案

以下代码应该有所帮助。如果您还没有它,请安装 devel module ,它给你一个很棒的功能,叫做 dpm()这会将数组/对象的内容打印到消息区域。

// Get some nodes ids
$nids = db_query('SELECT nid FROM {node}')->fetchCol();

// Load up the node objects
$nodes = node_load_multiple($nids);

// This will print the node object out to the messages area so you can inspect it to find the specific fields you're looking for
dpm($nodes);

// I guess you'll want to do something like this:
$terms = array();

foreach ($nodes as $node) {
// Load the taxonomy term associated with this node. This will be found in a field as this is how taxonomy terms and nodes are related in D7
$term = taxonomy_term_load($node->field_vocab_name['und'][0]['tid']);

// Set up the array
if (!isset($terms[$term->name])) {
$terms[$term->name] = array();
}

// Create some markup for this node
$markup = '<h3>' . l($node->title . ' ' . $node->field_other_field['und'][0]['value'], "node/$node->nid") . '</h3>';

// Add an image
$image = theme('image', array('path' => $node->field_image['und'][0]['uri'], 'alt' => $node->title));
$markup.= $image;

// Add the markup for this node to this taxonomy group's list
$terms[$term->name][] = $markup;
}

// Make up the final page markup
$output = '';
foreach ($terms as $term_name => $node_list) {
$output .= '<h2>' . check_plain($term_name) . '</h2>';
$output .= theme('item_list', array('items' => $node_list));
}

return $output;

希望有帮助

关于Drupal 7,不确定如何从查询数据中正确主题化我的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7293391/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com