显示相似节点

发布于 2024-10-12 21:35:04 字数 1053 浏览 7 评论 0原文

我今天在使用 Drupal 时遇到了一个问题。

我想在页面上显示一个节点(产品),并在该节点下方显示 3 个相似的节点(产品)。类似的是:具有相同的分类ID或附加有“升级”标签。

我尝试将相关节点制作成一个视图,仅当我们位于产品页面时,该视图才显示为块。我对此并没有深入了解。

我的第二个想法是制作一个面板页面,其中有两个视图,一个用于产品,一个用于相关产品。我对此也没有深入了解。

有谁知道实现此目标的最简单方法?

更新:

我已经尝试了这两个答案,但我没有收到任何相关产品。执行的 SQL 查询(术语 id = 1)是:

SELECT node.type AS node_type, node.title AS node_title, node.nid AS nid, node.created AS node_created FROM  {node} node INNER JOIN {taxonomy_index} taxonomy_index_value_0 ON node.nid = taxonomy_index_value_0.nid AND taxonomy_index_value_0.tid = :views_join_condition_0 WHERE (( (node.type IN ('product')) AND (taxonomy_index_value_0.tid AND '') AND( (taxonomy_index_value_0.tid IN ('1')) ))) ORDER BY node_created DESC LIMIT 10 OFFSET 0

当我手动执行查询并从查询中删除 AND (taxonomy_index_value_0.tid AND '') 时,我确实收到了相关产品。

有谁知道导致代码添加到查询中的原因以及如何修复它?

更新2: 我已删除“每个参数允许多个术语”,现在正在获取相关产品。但我不知道这对我的网站意味着什么。

更新3: 顺便说一句,我正在使用 Drupal 7。

I've somewhat ran in to a problem with Drupal today.

I would like to display a node (Product) on a page, and below that node, I'd like to display 3 similar nodes (Products). Similar being: having the same taxonomy id or having a "promoted" tag attached to it.

I've tried crafting the related nodes into a view which is being displayed as a block, only when we're on a product's page. I didn't get far with this.

My second thought was making a panel page with 2 views on it, one for the product, and one for the related products. I also didn't get far with this.

Does anybody know the easiest way to accomplish this?

Update:

I have tried both answers, I am not receiving any related products though. The SQL query that's executed (term id = 1) is:

SELECT node.type AS node_type, node.title AS node_title, node.nid AS nid, node.created AS node_created FROM  {node} node INNER JOIN {taxonomy_index} taxonomy_index_value_0 ON node.nid = taxonomy_index_value_0.nid AND taxonomy_index_value_0.tid = :views_join_condition_0 WHERE (( (node.type IN ('product')) AND (taxonomy_index_value_0.tid AND '') AND( (taxonomy_index_value_0.tid IN ('1')) ))) ORDER BY node_created DESC LIMIT 10 OFFSET 0

When I manually execute the query and remove AND (taxonomy_index_value_0.tid AND '') from the query I do receive the related products.

Does anybody know what causes the code to be added to the query and how to fix it?

Update 2:
I've removed the "Allow Multiple Terms per Argument" and am now getting the related products. I don't know what this means for my site though.

Update 3:
I am using Drupal 7 by the way.

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

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

发布评论

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

评论(3

顾铮苏瑾 2024-10-19 21:35:04

使用面板覆盖节点视图。并创建一个带有“taxonomy id argument”的视图块,您需要选择默认参数选项作为 PHP 代码并放置此代码。

$node = node_load(arg(1));
if($node) {
    foreach($node->taxonomy as $term) {
        $term = $term->tid;
        return $term;
    }   
}

我刚刚启动了一个使用面板+视图魔法的网站。 http://sgigulf.org/culture/synopsis-of-performers -由 sgi-gulf 展示

Override your node view with panels. And create a view block with 'taxonomy id argument', you need to choose default argument options as PHP Code and place this code.

$node = node_load(arg(1));
if($node) {
    foreach($node->taxonomy as $term) {
        $term = $term->tid;
        return $term;
    }   
}

I just launched a site using panels + views magic. http://sgigulf.org/culture/synopsis-of-performers-showcased-by-sgi-gulf

笔落惊风雨 2024-10-19 21:35:04

看一下相关内容模块。以下模块和一些教程的链接:

你说你显示器有问题。在这种情况下,请将上述说明中的视图设为一个块,并将其显示在节点内容下方的区域中,尽管这假设您的主题中有一个区域直接位于您的内容下方。

Take a look at the RelatedContent module. Links to the module and a couple of tutorials below:

You say you're having trouble with the display. In that casea, make the view from the above instructions a block, and have it display in a region that's below the node content, though that assumes there's a region in your theme directly below your content.

素罗衫 2024-10-19 21:35:04

当您更改为“内爆”中的“+”是“或”时,您可以有多个项

$node = node_load(arg(1));
if ($node) {
    $ret = array();
    foreach ($node->taxonomy as $term) {
        $ret[] =  $term->tid;
    }   
    return implode('+', $ret);
}
return '';

。如果您想要 AND,则使用“,”代替

You can have multiple terms when you change to

$node = node_load(arg(1));
if ($node) {
    $ret = array();
    foreach ($node->taxonomy as $term) {
        $ret[] =  $term->tid;
    }   
    return implode('+', $ret);
}
return '';

The '+' in implode is OR. If you want AND, than use ',' instead

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