2013-04-20 42 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