简体   繁体   English

如何在Drupal 6中自定义节点内容的输出?

[英]How to customize the output of node content in Drupal 6?

I am looking to customize the templated output of the $content variable in node.tpl.php Can you tell me how I could achieve this? 我正在寻找在node.tpl.php中自定义$ content变量的模板输出的方法,您能告诉我如何实现吗? Is is possible with another template file? 是否可以使用另一个模板文件?

The reason for this is to achieve AJAX pagination thus I need an ID on node_body and also to pull out the paging nav from this same DIV. 这样做的原因是要实现AJAX分页,因此我需要在node_body上有一个ID,并且还要从同一DIV中提取分页导航。

Any help appreciated! 任何帮助表示赞赏!

Copy the node.tpl file and rename it to node- contenttypename .tpl.php. 复制node.tpl文件,并将其重命名为node- contenttypename .tpl.php。 After doing this you can print the fields using this code 完成此操作后,您可以使用以下代码打印字段

print $node->field_name[0]['view'] ?> 打印$ node-> field_name [0] ['view']?>


to print body use this code 打印主体使用此代码

print strip_tags($node->content ['body']['#value']); 打印strip_tags($ node-> content ['body'] ['#value']);


to print gallery use this code or you can use views 打印画廊使用此代码,也可以使用视图


print if($node->field_gallery[0]['view']==null){ print " "; 打印if($ node-> field_gallery [0] ['view'] == null){打印“”; } else }其他
{ {

foreach ((array)$node->field_gallery as $item) { print $item['view'] foreach((array)$ node-> field_gallery as $ item){print $ item ['view']


i hope you can get ideas using this code. 我希望您可以使用此代码获得想法。
You can see example from this live site http://www.richtown.ae/?q=content/most-wanted-property-one-bed-residences-dial-0555456012-0 您可以从此实时网站上看到示例,网址为http://www.richtown.ae/?q=content/most-wanted-property-one-bed-residences-dial-0555456012-0
Thanks http://www.richtown.ae 谢谢http://www.richtown.ae

You need to delete the $content variablee from node.tpl.php and use the separate fields of $node. 您需要从node.tpl.php中删除$ content变量,并使用$ node的单独字段。 You can view the fields with print_r($node) 您可以使用print_r($ node)查看字段

Yes you can create another template file for that particular content type. 是的,您可以为该特定内容类型创建另一个模板文件。 using naming convention node-[content-type-name].tpl.php Naming convention of template file is very much important in Drupal. 使用命名约定node- [content-type-name] .tpl.php模板文件的命名约定在Drupal中非常重要。 Put this file into templates folder of theme directory. 将此文件放入主题目录的模板文件夹。 and print $node and replace $content variable with the fields you want. 并打印$ node并将$ content变量替换为所需的字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM