显示相似节点 [英] Displaying similar nodes

查看:23
本文介绍了显示相似节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我在使用 Drupal 时遇到了一些问题.

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

我想在页面上显示一个节点(产品),在该节点下方,我想显示 3 个相似的节点(产品).相似之处:具有相同的分类 ID 或附加了提升"标签.

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.

我的第二个想法是制作一个面板页面,上面有 2 个视图,一个用于产品,另一个用于相关产品.我也没有走得太远.

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?

更新:

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

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

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

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?

更新 2:我已经删除了每个参数允许多个条款",现在正在获取相关产品.我不知道这对我的网站意味着什么.

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.

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

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

推荐答案

用面板覆盖您的节点视图.并创建一个带有分类id参数"的视图块,您需要选择默认参数选项作为PHP代码并放置此代码.

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

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

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

这篇关于显示相似节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆