使用 CCK 在 Drupal 6 模板中添加链接字段
晚上好,
我正在使用 Drupal 6、CCK 模块和链接字段类型。全部已安装并激活。
我创建了一个名为“滑块”的自定义内容类型。用户可以上传图像、标题和预告片。我为该滑块内容类型创建了一个自定义字段,以及一个名为“链接”的字段,字段名称为:“field_link_test”。
我创建了一个条目,填写了所有数据,包括该链接字段类型的 URL,然后单击“保存”。在views-view-table--slider.tpl.php中,我添加了:
<a href="<?php print $node->field_link_test[0]['url'] ?>">Learn More</a>
但是在前端,除了该链接之外的所有内容都显示。我还尝试清空 Drupal 缓存。
有什么想法吗?
更新下面的模板代码,一切正常,除了新的链接值不输出任何内容。
<div id="slider">
<div class="slider-holder">
<?php foreach($rows as $row): ?>
<div class="slide">
<?php print $row['field_image_fid'] ?>
<div class="info-slide">
<h2><?php print $row['title'] ?></h2>
<p><?php print strip_tags($row['teaser']) ?></p>
<a href="<?php print $node->field_link_test[0]['url'] ?>">Learn More</a>
</div><!--INFO-SLIDE-->
</div><!--SLIDE-->
<?php endforeach ?>
</div><!--SLIDER-HOLDER-->
<div id="control">
</div>
</div><!--SLIDER-->
Good Evening,
I'm using Drupal 6, CCK Module, and the Link Field Type. All are installed and activated.
I created a custom content type called Slider. A user can upload an image, a title, and a teaser. I created a custom field for that slider content type as well as one called Link with the field name: "field_link_test".
I created an entry, filled in all of the data including a URL for that link field type and clicked "Save". In views-view-table--slider.tpl.php, I added:
<a href="<?php print $node->field_link_test[0]['url'] ?>">Learn More</a>
but on the front end, everything shows except for that link. I also tried emptying the Drupal cache.
Any ideas?
Update template code below, which all works fine, except for the new link value outputs nothing.
<div id="slider">
<div class="slider-holder">
<?php foreach($rows as $row): ?>
<div class="slide">
<?php print $row['field_image_fid'] ?>
<div class="info-slide">
<h2><?php print $row['title'] ?></h2>
<p><?php print strip_tags($row['teaser']) ?></p>
<a href="<?php print $node->field_link_test[0]['url'] ?>">Learn More</a>
</div><!--INFO-SLIDE-->
</div><!--SLIDE-->
<?php endforeach ?>
</div><!--SLIDER-HOLDER-->
<div id="control">
</div>
</div><!--SLIDER-->
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简单的可能性(您可能已经检查过,但只是为了让它们摆脱困境):
否则,如果没有一些代码就很难区分来分析。您能否发布整个views-view-table--slide.tpl.php,如果可能的话,您导出的视图或导出视图的链接?
编辑
现在我有机会了解您的观点,我做了一些应该有所帮助的更改。
您的链接 URL 未显示的原因是您在视图中包含“节点:链接”字段,而不是“内容:链接 (field_link_test)”字段。第一个将仅链接回原始节点而不是您的自定义链接。另外,我不认为你可以从views-view-table中调用
$node
变量(至少,当我打印它时我没有得到任何东西。相反,你可以使用$row
变量。我有一个模板版本,它在“link_test”字段中打印出带有“了解更多”标签的 URL。我将“了解更多”文本放在视图本身中。将更容易编辑并且可以更好地使用链接 CCK 类型(默认情况下会添加您在节点编辑屏幕中添加的标题)
视图导出位于此处:http://pastebin.me/0ed2942f6953cb00cab1bd5386058a13。您可以将其导入回您的网站,但您可能需要先克隆原始视图以进行备份,以便如果这不是您想要的,您可以使用旧版本。
更新后的 tpl 是:
如果您有任何问题/疑问,请告诉我。
The easy possibilities (which you've probably checked, but just to get them out of the way):
Otherwise, it's hard to tell without some code to analyse. Could you post your entire views-view-table--slide.tpl.php and if possible, your exported view or a link to the exported view?
EDIT
Now that I've had a chance to look at your view, I've made a couple of changes that should help.
The reason your link URL isn't showing is that you're including the "Node: Link" field in your View instead of the "Content: Link (field_link_test)" field. The first one will just link back to the original node rather than your custom link. Also, I don't think you can call the
$node
variable from views-view-table (at least, I don't get anything when I print it. Instead, you can use the$row
variable.I have a version of your template that prints out the URL in the field "link_test" with the label "Learn More." I put the "Learn More" text in the View itself as that'll be easier to edit and works better with the Link CCK type (which by default will want to add a title you add in the node edit screen).
The view export is here: http://pastebin.me/0ed2942f6953cb00cab1bd5386058a13. You can import this back into your site, but you may want to clone your original View first to make a backup, so that if this isn't what you want, you can use your old version.
The updated tpl is:
Let me know if you have any issues/questions.
您确定模板已被选中(在 href 上方添加
heavymark
...它会显示吗?)?
如果出现上述情况,请在锚标记上方添加 var_dump($node) 并发布输出,以便我们可以更好地了解其中的内容(您可能希望启用 XDebug 这样你就可以得到更好的格式化输出(如果它还没有打开的话)。
Are you sure the template is getting picked up (add
<p>heavymark</p>
above the href... does it show up?)?If above shows up, add a var_dump($node) above the anchor tag and post the output so we can get a better idea of what's there (you probably want to enable XDebug so you get better formatted output, if its not on already).
确保将链接字段添加到字段部分的视图中。这应该允许它在模板文件中进行主题化。如果您仍然没有看到它,请尝试使用
print_r($rows,1);
或 print_r 的某个变量来查看可用于主题化的所有行。
Make sure you add the link field to the view in the fields section. This should allow it to be themeable from within your template file. If you are still not seeing it, try using
print_r($rows,1);
or some variable of print_r to view all the rows that are available to be themed.