Drupal 7,不确定如何根据查询数据正确设置我的输出主题

发布于 2024-12-02 13:26:19 字数 1084 浏览 1 评论 0原文

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

所以我想我应该纠正一个模块。我已经编写了 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);

非常感谢您花时间帮助我,并提前致谢。< /强>

I’ve been using Views to selectively returned nodes, but right now I want to return my nodes and use the Taxonomy term as a group header. I can't see anyway to get Views to do this for me, other then create multiple views on one page.

So I thought I'd right a module. I've written the SQL to return the correct nodes, but I can't work out how to send them to the themeing engine properly. I would like some advice on how to go about this, my tutorial book has examples of building a list as shown below.

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

now I want to return my nodes attached image file in Teaser mode, and the title of the node, plus (and I dont want to get ahead of myself) I may also want a couple of the addition node fields appended to the title. Should be easy right? I can't work it out at all.

I have wrangled my way around it (a bit) by using what I'm sure is a non drupal method which looks a bit like this, trouble is I can't get my output to work with ColorBox module, so I'm thinking if I can get official Teaser node data out it might work better, and i'd feel better knowing I was doing things in a drupaly way :)

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);

Really appreciate any time you take to help me out and thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感悟人生的甜 2024-12-09 13:26:19

下面的代码应该有帮助。如果您还没有,请安装 devel 模块,它为您提供了一个很棒的功能,称为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;

希望有帮助

The following code should help. If you don't already have it, install the devel module, it gives you a wonderful function called dpm() which will print the contents of an array/object to the messages area.

// 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;

Hope that helps

眼泪也成诗 2024-12-09 13:26:19

您可以获得按分类术语对返回的节点进行分组的视图。假设您使用的是 field 视图类型,只需添加分类字段,然后添加 Format:Unformatted list | 。设置 单击右侧的“设置”,然后选择您的分类字段作为分组字段。

注意:如果您不使用字段视图类型,或者不使用无格式列表,那么说明将是上述内容的变体。

You can get views to group the returned nodes by the taxonomy term for you. Assuming you are using a field view type, just add the taxonomy field and then where it says Format:Unformatted list | Settings click on Settings at the right hand side and choose your taxonomy field as the grouping field.

Note: if you are not using a field view type, or if you are not using unformatted list then the instructions will be a variation of the above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文