简体   繁体   English

如何在WordPress站点上运行WordPress插件“数据表”并从footer.php启动脚本?

[英]How can I run WordPress-plugin “Data Tables” on a WordPress-site and start the script from footer.php?

So I don't study anything that has anything to do with code but we had a small web production course and I got a residue task from that time. 所以我不研究任何与代码有关的东西,但是我们有一个小的网络制作课程,那时我得到了一个残留任务。 Basically we learned the basics of setting up a homepage (html, css, FTP-servers etc) and then installed WordPress on that site and made a child theme. 基本上我们学习了设置主页(html,css,FTP服务器等)的基础知识,然后在该网站上安装了WordPress并制作了一个子主题。 So far so good. 到现在为止还挺好。

But in the task I have left we're supposed to install a javascript-plugin called Data Tables ( http://datatables.net ) on that site. 但在我离开的任务中,我们应该在该网站上安装一个名为Data Tables( http://datatables.net )的javascript插件。 I'm sure this is very easy but like I said I know very little about code and imo there is information missing in the task description. 我确信这很容易,但就像我说我对代码和imo知之甚少,任务描述中缺少信息。 My teacher is very unhelpful when I ask for advice. 当我征求意见时,我的老师非常无益。

I got the plugin to work locally on a simple html-page, no problem, but I don't understand how to go about it to get it to work on the WordPress-site. 我有一个插件在一个简单的html页面上本地工作,没问题,但我不明白如何去使它在WordPress网站上工作。 In the task description we're asked to add this code to the site's functions.php: 在任务描述中,我们要求将此代码添加到站点的functions.php中:

wp_register_script( 'ScriptName_1', 'https://cdn[...]', null, null, true ); 
wp_enqueue_script(' ScriptName_1');



 wp_register_style( 'StyleName_1', 
'https://cdn[...]' ); 
wp_enqueue_style('StyleName_1'); 

I understand CDN-links and had no problem linking it in locally but then I never had to do any PHP. 我理解CDN链接并且没有问题在本地链接它然后我从来没有做任何PHP。 When I just paste this into functions.php(but with the right links of course) it doesn't seem to work. 当我把它粘贴到functions.php中时(当然使用正确的链接)它似乎不起作用。 This is the first thing I'd really appreciate some help with. 这是我真正感谢一些帮助的第一件事。 How should the code go into functions.php? 代码如何进入functions.php?

Then the task says to put the code that starts the script in the footer.php and the code looks like this: 然后任务说要将启动脚本的代码放在footer.php中,代码如下所示:

(function($) {
$(document).ready(function(){ $('#correct_id').codeThatStartsPlugin ;
}); }(jQuery));

I understand this code, the #correct_id is to be replace with an ID for tables that we want to be affected by the Data Tables plugin and the codeThatStartsPlugin is "dataTable" according to their guide. 我理解这段代码,#correct_id将替换为我们希望受Data Tables插件影响的表的ID,而codeThatStartsPlugin是根据他们的指南“dataTable”。

But my site's child theme doesn't have a footer.php and even if I create one I don't understand in which format I should put it there. 但我的网站的子主题没有footer.php,即使我创建一个我不明白我应该把它放在那里的格式。 How do I write JS in PHP, or rather just how do I start this plugin from footer.php? 如何在PHP中编写JS,或者更确切地说如何从footer.php启动此插件? I tried to copy the footer.php from the mother theme and just add it within a -tag but that didn't seem to do it either. 我试图从母主题中复制footer.php并将其添加到-tag中,但似乎也没有。

So like I said, this is probably very easy for someone who knows code but I don't and my teacher is refusing to give me any advice. 就像我说的那样,对于那些知道代码的人来说这可能很容易,但我不这样做,我的老师拒绝给我任何建议。 I get that coders don't like being asked to solve other people's problems all the time, but I am humbly asking for help and hoping this is so easy that some coder out there will have mercy on me. 我觉得编码员不喜欢被要求一直解决别人的问题,但是我谦卑地寻求帮助,希望这很容易让一些编码人员怜悯我。

In your ChilTheme there should be php file with the name functions.php where you place your following code. 在你的ChilTheme中应该有一个名为functions.php php文件,你functions.php在其中放置以下代码。

  1. You need to change the CDN Links with the right ones you need to link to. 您需要使用需要链接的正确CDN链接来更改CDN链接。 They are now empty(placeholder) 它们现在是空的(占位符)

      wp_register_script( 'ScriptName_1', 'https://cdn[...]', null, null, true); wp_enqueue_script(' ScriptName_1'); 

    This functions tells us that we have to put the corrosponding JavaScript function in the footer, the lates argument in the functions is set to true 这个函数告诉我们必须将相应的JavaScript函数放在页脚中,函数中的lates参数设置为true

      wp_register_style( 'StyleName_1', 'https://cdn[...]' ); wp_enqueue_style('StyleName_1'); 

    create a footer file with the following name footer.php under your child theme folder and then put the code in the footer.php file you created. 在您的子主题文件夹下创建一个名为footer.php的页脚文件,然后将代码放入您创建的footer.php文件中。

    (function($) { $(document).ready(function(){ $('#correct_id').codeThatStartsPlugin ; }); }(jQuery)); (function($){$(document).ready(function(){$('#correct_id')。codeThatStartsPlugin;});}(jQuery));

As you said you need to put the correct id selecter here ('#correct_id') 如你所说,你需要在这里放置正确的id选择器('#correct_id')

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

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