简体   繁体   English

如何将PHP或Javascript代码添加到自定义内容类型

[英]How to add PHP or Javascript code to a custom content type

I am working with Drupal 7.17. 我正在使用Drupal 7.17。

I have a custom content type I created called Sidebar Ad (machine name sidebar_ad) that I want to add Javascript and PHP to. 我创建了一个自定义内容类型,称为Sidebar Ad(机器名称sidebar_ad),我想向其中添加Javascript和PHP。 From what I understand, in the templates directory of the theme I am working with, I need to create a file called 'page--sidebar_ad.tpl.php' and I can put PHP and Javascript code in there, and it will only run in blocks and pages that contain the custom content type Sidebar Ad. 据我了解,在我正在使用的主题的模板目录中,我需要创建一个名为“ page--sidebar_ad.tpl.php”的文件,然后将PHP和Javascript代码放入其中,并且该文件只能运行在包含自定义内容类型“边栏广告”的块和页面中。

I am trying this out with one of the stock themes, Bartik, and it is not working for me. 我正在使用股票主题之一Bartik进行尝试,但它对我没有用。 I tried it by copying the page.tpl.php file, renaming it page--sidebar_ad.tpl.php, and adding a bit of text in a few places - at the top of the php file, and in the content div. 我通过复制page.tpl.php文件,将其重命名为page-sidebar_ad.tpl.php并在php文件顶部和内容div中的几个位置添加了一些文本来进行尝试。 But I don't see anything change on the pages on my site that contain that custom content type. 但是,我看不到网站上包含该自定义内容类型的页面上的任何更改。

Is there something I am missing? 我有什么想念的吗?

Most likely the thing you're missing is flushing Drupal's cache...any time you add a hook or template file, you need to flush the cache so the various registries can pick it up. 您丢失的东西很可能是刷新Drupal的缓存...每次添加钩子或模板文件时,都需要刷新缓存,以便各个注册表都可以提取它。

In the case of an overridden page template file you also need a copy of the standard page.tpl.php file in your theme. 对于覆盖的页面模板文件,您还需要主题中标准page.tpl.php文件的副本。 Same goes for the node template and most likely others, you need the original in there for the overrides to work. 节点模板和其他模板也一样,您需要原始模板才能使覆盖生效。

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

相关问题 如何在Wordpress文件“ single.php”中添加自定义javascript代码 - How to add custom javascript code in the Wordpress file “single.php” 如何在Drupal 7的内容类型中添加自定义字段 - How to add custom field in the content type of Drupal 7 如何在 woocommerce 上的 php 代码上添加更多 id 以用于产品的自定义内容? - how can i add more ids on php code on woocommerce for custom content for products? 如何使用php代码将woocommerce产品添加到自定义Product_type? - How to add a woocommerce product to the custom Product_type using php code? 将Javascript添加到php代码中 - Add Javascript to php code 在Wordpress中查看自定义帖子类型时如何添加一些内容? - How to add some content when viewing custom post type in wordpress? 在php代码中添加javascript和在javascript中添加php代码 - Add javascript in php code and php code in Javascript 如何使用PHP在Google Shopping Content API中添加自定义属性? - How to add Custom Attributes in Google shopping content api with php? 如何在带有html内容的php文件中添加javascript? - how to add javascript inside php file with html content? 如何在“之后”添加代码 </article> 在Wordpress的content-page.php中? - How to add code after “</article>” in content-page.php in Wordpress?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM