2013-04-20 29 views
-1

我的目標是將此javascript代碼轉換爲wordpress php,並且我不知道如何去做,而不會收到錯誤消息。最終目標是讓JavaScript遊戲簡單地嵌入到wordpress頁面中。我已經檢查了其他幾十篇文章,但沒有一篇足夠具體地描述這樣的代碼。我正在尋找包含在PHP中的代碼僅在虛擬網站鏈接下方。希望你能幫助我!提前致謝。php中的高級javascript遊戲

<script src="http://www.java.com/js/deployJava.js"></script> 
<script> 
    var attributes = { 
    codebase: 'my_website', 
    code: 'vNES.class', 
    archive: 'my_website', 
    width: 512, 
    height: 480 
    }; 
    var parameters = { 
    sound: "on", 
    timeemulation: "on", 
    fps: "off", 
    stereo: "off", 
    rom: "my_website/game.zig", 
    showsoundbuffer: "off", 
    scale: "on", 
    scanlines: "off", 
    nicesound: "on", 
    romsize: 40976 
    }; 
    deployJava.setInstallerType('online'); 
    // deployJava.setInstallerType('kernel'); 
    if (deployJava.versionCheck('1.5+')) { 
    deployJava.runApplet(attributes, parameters, '1.5'); 
    } else { 
    document.write("<br />"); 
    document.write("<b style='color: red;'>Your browser does not appear to have Java installed.</b>"); 
    document.write("<b><a href='#' onclick='javascript:deployJava.installLatestJRE();'>Click here to install the Java run-time.</a></b><br /><br />"); 
    if (navigator.userAgent.indexOf("Chrome") != -1 && navigator.userAgent.indexOf("Mac OS X") != -1) { 
     document.write("<b style='color: red;'>"); 
     document.write("Please note that Google Chrome under MacOS X does currently not support Java applets, so consider temporarily switching to Firefox or Safari if you are a MacOS X user.<br /><br />"); 
     document.write("</b>"); 
    } 
    document.write("This page has been tested and works with the latest versions of the following Windows browsers: Firefox, Google Chrome, Internet Explorer, Opera and Safari.<br /><br />"); 
    document.write("This page has been tested and works with the latest versions of the following MacOS X browsers: Firefox, Opera and Safari.<br /><br />"); 
    } 
</script> 

回答

0

您可以發佈您收到的錯誤消息嗎?從我的wordpress經驗來看,這應該是非常簡單的。在wordpress中,你想讓它顯示出來嗎?在索引頁面上?

如果是這種情況,你可以回顯每一行或者只是通過關閉和打開php標籤來轉義腳本。這個想法和上面的document.write(「...」)是一樣的。

只需要難逃「標記

echo"<script src=\"http://www.java.com/js/deployJava.js\"></script>"; 

也可以...添加代碼像下面

<?php (php code...) ?> 

<script type="text/javascript"> 
window.location = "http://www.google.com/" 
</script> 

<?php (php code continues...) ?> 

希望這有助於在WordPress的,我會去到文件並編輯索引文件,但也取決於你想把它放在wordpress中的位置。無論哪種方式,你將不得不編輯文件才能正常工作。

你也可以添加一個新頁面到wordpres s ...

在您的主題文件夾(位於/ wp-content/themes/themename /下)中複製post.php。

文件重命名爲someNameYouWant.php

在頂部,現在加上:

<?php 
/* 
Template Name: templatename 
*/ 
?> 

您可以修改此文件(使用PHP)到包括其他文件或任何你需要的。

然後在您的wordpress博客中創建一個新頁面,在頁面編輯屏幕中,您會在右側的「屬性」小部件中看到一個「模板」下拉菜單。選擇你的新模板併發布頁面。

您的新頁面將使用templatename.php中定義的php代碼

+0

太棒了!謝謝,你是對的...我似乎把代碼粘貼到了index.php的錯誤部分,但現在它工作得很好。我只是簡單地在你的第二個例子中建議的php代碼之間插入它。感謝您的時間,先生 – user2301344 2013-04-20 07:16:46