1

所以我有一个祈祷时间脚本,我想将它嵌入到 wordpress 页面中。这是它的链接:http: //praytimes.org/manual/

基本上有一个 PrayTimes.js 文件,我试图将其包含到 header.php/page.php 文件中但没有成功。

我将在常规 HTML 页面中发布的代码如下所示:

<!DOCTYPE html>
<html>
<head>
    <title> Daily Prayer Timetable </title>
    <style>
        body, td, th {font-family: verdana; font-size: 12px; color: #404040;}
        #timetable {border-width: 1px; border-style: outset; border-collapse: collapse; border-color: gray; width: 9em;}
        #timetable td, #timetable th {border-width: 1px; border-spacing: 1px; padding: 2px 4px; border-style: inset; border-color: #CCCCCC;}
        #timetable th {color:black; text-align: center; font-weight: bold; background-color: #F8F7F4;}
    </style>
</head>

<body>

<script type="text/javascript" src="../PrayTimes.js"></script>

<br>
<p align="center">Waterloo, ON, Canada<p>
<div align="center" id="table"></div>

<script type="text/javascript">

    var date = new Date(); // today
    var times = prayTimes.getTimes(date, [43, -80], -5);
    var list = ['Fajr', 'Sunrise', 'Dhuhr', 'Asr', 'Maghrib', 'Isha', 'Midnight'];

    var html = '<table id="timetable">';
    html += '<tr><th colspan="2">'+ date.toLocaleDateString()+ '</th></tr>';
    for(var i in list)  {
        html += '<tr><td>'+ list[i]+ '</td>';
        html += '<td>'+ times[list[i].toLowerCase()]+ '</td></tr>';
    }
    html += '</table>';
    document.getElementById('table').innerHTML = html;

</script>

</body>
</html>

我只是不确定如何将其嵌入到 Wordpress 页面中。我只需要使用一次。

4

2 回答 2

0

您应该在head标签之间放置脚本。

<!DOCTYPE html>
<html>
<head>
    <title> Daily Prayer Timetable </title>
    <style>
        body, td, th {font-family: verdana; font-size: 12px; color: #404040;}
        #timetable {border-width: 1px; border-style: outset; border-collapse: collapse; border-color: gray; width: 9em;}
        #timetable td, #timetable th {border-width: 1px; border-spacing: 1px; padding: 2px 4px; border-style: inset; border-color: #CCCCCC;}
        #timetable th {color:black; text-align: center; font-weight: bold; background-color: #F8F7F4;}
    </style>
    <script type="text/javascript" src="../PrayTimes.js"></script>
</head>

<body>

<br>
<p align="center">Waterloo, ON, Canada<p>
<div align="center" id="table"></div>

<script type="text/javascript">

    var date = new Date(); // today
    var times = prayTimes.getTimes(date, [43, -80], -5);
    var list = ['Fajr', 'Sunrise', 'Dhuhr', 'Asr', 'Maghrib', 'Isha', 'Midnight'];

    var html = '<table id="timetable">';
    html += '<tr><th colspan="2">'+ date.toLocaleDateString()+ '</th></tr>';
    for(var i in list)  {
        html += '<tr><td>'+ list[i]+ '</td>';
        html += '<td>'+ times[list[i].toLowerCase()]+ '</td></tr>';
    }
    html += '</table>';
    document.getElementById('table').innerHTML = html;

</script>

</body>
</html>
于 2012-04-19T07:08:50.410 回答
0

您可以修改主题标题模板。

但是这样做的正确方法是将您的内联脚本放在一个单独的 js 文件中,并用于wp_enqueue_script在您的页面中添加两个 js 文件。

于 2012-04-19T07:20:43.430 回答