Drupal 6:在views_customfield中使用php显示CCK字段值

发布于 2024-09-05 20:55:39 字数 1145 浏览 4 评论 0原文

已排序

http://drupal.org/node/467190#comment-2068324


嗨朋友们,

我花了一整天的时间寻找但找不到:(

如何在views_customfield中用php显示CCK字段值?我尝试了下面的,但没有结果

$node->field_homepage_linking[0]["view"]

$node->field_homepage_linking[0]["value"]

value_get('field_homepage_linking')

感谢帮助!

$node->field_homepage_linking[0]["视图"]

这适用于 tpl.php 文件,而不适用 在视图模块面板中工作如下 (截图)

替代文本http://img.skitch.com/20100616-dy2pxkdichni7nu1h747tptfa8.jpg

<?php 
 if ($node->field_homepage_linking[0]["view"] == 1) { ?>
    <a href="<?php print drupal_get_path_alias("node/" .$data->nid) ; ?>" title="<?php print $data->node_title; ?>">
<?php } ?>
<?php print $data->node_title; ?>
<?php  if ($node->field_homepage_linking[0]["view"] == 1) { ?>
    </a>
<?php } ?>

SORTED

http://drupal.org/node/467190#comment-2068324


Hi friends,

I've spent all day to find but can't find :(

How can I display CCK Field value with php in views_customfield? I tried the ones below, but no result

$node->field_homepage_linking[0]["view"]

$node->field_homepage_linking[0]["value"]

value_get('field_homepage_linking')

Appreciate helps!!

$node->field_homepage_linking[0]["view"]

this works in tpl.php files, not not
working in View Module panel as below
(screenshot)

alt text http://img.skitch.com/20100616-dy2pxkdichni7nu1h747tptfa8.jpg

<?php 
 if ($node->field_homepage_linking[0]["view"] == 1) { ?>
    <a href="<?php print drupal_get_path_alias("node/" .$data->nid) ; ?>" title="<?php print $data->node_title; ?>">
<?php } ?>
<?php print $data->node_title; ?>
<?php  if ($node->field_homepage_linking[0]["view"] == 1) { ?>
    </a>
<?php } ?>

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

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

发布评论

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

评论(3

榕城若虚 2024-09-12 20:55:45

这对我有用:
customfield 中用于加载 cck 字段的 PHP 代码

$node = node_load($data->nid, NULL, TRUE);
echo $node->field_name_of_field[0]["value"];

This works for me:
The PHP code in customfield for loading cck field

$node = node_load($data->nid, NULL, TRUE);
echo $node->field_name_of_field[0]["value"];
红ご颜醉 2024-09-12 20:55:43

看起来像是一个笔误。

$node->field_homepage_linking["0"]["value"]

应该是:

$node->field_homepage_linking[0]["value"]

虽然,如果它是 CCK 字段,为什么不将其添加为字段呢?所有 CCK 字段都位于字段的内容类别下。另外,为此,您需要加载 $node 对象并准备好供视图使用,这也可能是您看不到任何内容的原因。

看起来您想要有条件显示。我不知道如何在自定义字段中执行此操作,但我已经使用特定字段的 .tpl 字段多次执行此操作。您可以将主题 tpl 文件添加到视图中并在其中包含 PHP 代码,还可以转储视图的 $row 和 $data 对象以查看必须使用哪些字段/值。

Looks like a clerical error.

$node->field_homepage_linking["0"]["value"]

Should be:

$node->field_homepage_linking[0]["value"]

Although, if its a CCK field, why not just add it as a Field? All CCK fields are under the Content category of the Fields. Also, to do this, you need the $node object loaded and ready to use by Views, which may also be why you aren't seeing anything.

Looks like you want to have a conditional display. I am not sure how to do this in Customfield, but I have done this many times with a .tpl field for particular fields. You can add theme tpl files to Views and have PHP code inside it, and also dump out the $row and $data object of views to see what fields/values you have to work with.

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