简体   繁体   English

如何将这个jQuery脚本添加到WordPress网站

[英]how to add this jquery script in to wordpress website

i liked this countdown script from http://www.jqueryscript.net/time-clock/Modern-Circular-jQuery-Countdown-Timer-Plugin-Final-Countdown.html and want to use this one to my wordpress website , i read some tutorials about how to put any script in wordpress but i could not understand exactly cause i am newbie , can you help me to do this step by step 我喜欢http://www.jqueryscript.net/time-clock/Modern-Circular-jQuery-Countdown-Timer-Plugin-Final-Countdown.html中的这种倒计时脚本,并希望将其用于我的wordpress网站,我阅读了一些有关如何在wordpress中放置任何脚本的教程,但我不完全理解我是新手,可以帮助我逐步进行此操作吗

now i will show the script author instructions to use this script on normal html page i want to do these steps also but in wordpress . 现在,我将向脚本作者说明如何在普通html页面上使用此脚本,我也想在Wordpress中执行这些步骤。

  1. Include the necessary javascript files at the end of the page. 在页面末尾包含必要的javascript文件。

     <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"> </script> <script type="text/javascript" src="js/kinetic.js"></script> <script type="text/javascript" src="../jquery.final-countdown.js"></script> 
  2. Include the required bootstrap 3 CSS in the head of the page. 在页面顶部包含必需的bootstrap 3 CSS。

     <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> 
  3. Create a countdown timer using the html structure like this: 使用html结构创建一个倒数计时器,如下所示:

     <div class="countdown-container container"> <div class="clock row"> <!-- days --> <div class="clock-item clock-days countdown-time-value col-sm-6 col-md-3"> <div class="wrap"> <div class="inner"> <div id="canvas_days" class="clock-canvas"></div> <div class="text"> <p class="val">0</p> <p class="type-days type-time">DAYS</p> </div> </div> </div> </div> <!-- hours --> <div class="clock-item clock-hours countdown-time-value col-sm-6 col-md-3"> <div class="wrap"> <div class="inner"> <div id="canvas_hours" class="clock-canvas"></div> <div class="text"> <p class="val">0</p> <p class="type-hours type-time">HOURS</p> </div> </div> </div> </div> <!-- minutes --> <div class="clock-item clock-minutes countdown-time-value col-sm-6 col-md-3"> <div class="wrap"> <div class="inner"> <div id="canvas_minutes" class="clock-canvas"></div> <div class="text"> <p class="val">0</p> <p class="type-minutes type-time">MINUTES</p> </div> </div> </div> </div> <!-- seconds --> <div class="clock-item clock-seconds countdown-time-value col-sm-6 col-md-3"> <div class="wrap"> <div class="inner"> <div id="canvas_seconds" class="clock-canvas"></div> <div class="text"> <p class="val">0</p> <p class="type-seconds type-time">SECONDS</p> </div> </div> </div> </div> </div> </div> 
    1. Add the following CSS snippet to your CSS file. 将以下CSS代码段添加到您的CSS文件中。

      html, body { height: 100%; html,正文{高度:100%; } html { background-image: url('../img/sample.jpg'); } html {background-image:url('../ img / sample.jpg'); background-position: center center; 背景位置:中心中心; background-repeat: no-repeat; 背景重复:不重复; background-size: cover; 背景尺寸:封面; } body { background-color: rgba(44,62,80 , 0.6 ); } body {background-color:rgba(44,62,80,0.6); background-image: url('../img/pattern.png'); 背景图片:url('../ img / pattern.png'); background-position: center; 背景位置:中心; background-repeat: repeat; 背景重复:重复; font-family: 'Raleway', 'Arial', sans-serif; 字体家族:“ Raleway”,“ Arial”,无衬线; } .countdown-container { position: relative; } .countdown-container {位置:相对; top: 50%; 最高:50%; -webkit-transform: translateY(-50%); -webkit-transform:translateY(-50%); -moz-transform: translateY(-50%); -moz-transform:translateY(-50%); transform: translateY(-50%); 转换:translateY(-50%); } .clock-item .inner { height: 0px; } .clock-item .inner {height:0px; padding-bottom: 100%; 底部填充:100%; position: relative; 职位:相对 width: 100%; 宽度:100%; } .clock-canvas { background-color: rgba(255, 255, 255, .1); } .clock-canvas {background-color:rgba(255,255,255,.1); border-radius: 50%; 边界半径:50%; height: 0px; 高度:0px; padding-bottom: 100%; 底部填充:100%; } .text { color: #fff; } .text {color:#fff; font-size: 30px; font-size:30px; font-weight: bold; font-weight:粗体; margin-top: -50px; 页边距:-50px; position: absolute; 位置:绝对; top: 50%; 最高:50%; text-align: center; 文本对齐:居中; text-shadow: 1px 1px 1px rgba(0, 0, 0, 1); 文本阴影:1px 1px 1px rgba(0,0,0,1); width: 100%; 宽度:100%; } .text .val { font-size: 50px; } .text .val {font-size:50px; } .text .type-time { font-size: 20px; } .text .type-time {font-size:20px; } @media (min-width: 768px) and (max-width: 991px) { .clock-item { margin-bottom: 30px; } @media(最小宽度:768像素)和(最大宽度:991像素){.clock-item {margin-bottom:30px; } } @media (max-width: 767px) { .clock-item { margin: 0px 30px 30px 30px; }} @media(最大宽度:767像素){.clock-item {边距:0像素30像素30像素30像素; } } }}

  4. Initialize the countdown timer and set the start time, end time and current time in the javascript. 初始化倒数计时器,并在javascript中设置开始时间,结束时间和当前时间。

      <script type="text/javascript"> $('.countdown').final_countdown({ start: '1362139200', end: '1388461320', now: '1387461319' }); </script> 
  5. All the default options. 所有默认选项。

     $(document).ready(function() { $('.countdown').final_countdown({ start: '1362139200', end: '1388461320', now: '1387461319', selectors: { value_seconds: '.clock-seconds .val', canvas_seconds: 'canvas_seconds', value_minutes: '.clock-minutes .val', canvas_minutes: 'canvas_minutes', value_hours: '.clock-hours .val', canvas_hours: 'canvas_hours', value_days: '.clock-days .val', canvas_days: 'canvas_days' }, seconds: { borderColor: '#7995D5', borderWidth: '6' }, minutes: { borderColor: '#ACC742', borderWidth: '6' }, hours: { borderColor: '#ECEFCB', borderWidth: '6' }, days: { borderColor: '#FF9900', borderWidth: '6' }}, function() { // Finish callback }); }); 

To add Javascript and CSS files inside Wordpress, you need to use wp_register_script and wp_register_style functions inside your functions.php theme file. 要在Wordpress中添加Javascript和CSS文件,您需要在functions.php主题文件中使用wp_register_scriptwp_register_style函数。

So let's translate every step: 因此,让我们翻译每个步骤:

Include the necessary javascript files at the end of the page. 在页面末尾包含必要的javascript文件。

You don't need to include jquery as it is already included by Wordpress. 您不需要包括jquery,因为它已经被Wordpress所包含。 Download kinetic.js and jquery.final-countdown.js , and add them into your theme folder in a js directory. 下载dynamic.jsjquery.final-countdown.js ,并将它们添加到js目录中的主题文件夹中。

Then in your functions.php add the following: 然后在您的functions.php中添加以下内容:

add_action('wp_enqueue_scripts', 'my_enqueue_scripts');
function my_enqueue_scripts() {
    wp_enqueue_script('kinetic', get_stylesheet_directory_uri() . '/js/kinetic.js', array('jquery'), '', true);
    wp_enqueue_script('countdown', get_stylesheet_directory_uri() . '/js/jquery.final-countdown.js', array('jquery'), '', true);
}

Include the required bootstrap 3 CSS in the head of the page. 在页面顶部包含必需的bootstrap 3 CSS。

In the same function, add the following line: 在同一函数中,添加以下行:

wp_enqueue_style('bootstrap_css', '//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css');

Create a countdown timer using the html structure like this 使用这样的html结构创建一个倒数计时器

See where you want to include it. 查看您想在哪里添加它。 If you want this on all the pages inside header, add this inside header.php in your theme folder. 如果要在标题内的所有页面上使用此功能,请将其添加到主题文件夹中的header.php中。

Add the following CSS snippet to your CSS file. 将以下CSS代码段添加到您的CSS文件中。

Just add the code inside your actual stylesheet. 只需在您的实际样式表中添加代码即可。

Initialize the countdown timer and set the start time, end time and current time in the javascript. 初始化倒数计时器,并在javascript中设置开始时间,结束时间和当前时间。

You could do this in your own js file. 您可以在自己的js文件中执行此操作。 Add a countdown.js file in your js folder, and enqueue it like before: 在您的js文件夹中添加一个countdown.js文件,并像之前一样使其入队:

wp_enqueue_script('countdown_script', get_stylesheet_directory_uri() . '/js/countdown.js', array('jquery'), '', true);

And in your countdown.js file: 在您的countdown.js文件中:

jQuery(document).ready(function($) {
    $('.countdown').final_countdown({
        start: '1362139200',
        end: '1388461320',
        now: '1387461319'
    });
});

That way it will prevent any conflict. 这样,它将防止任何冲突。

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

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