首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我以前有一个简单的HTML页面与脚本链接到js文件,为AI测试。如何链接或导入到我正在自己的pc上测试的wordpress站点

我以前有一个简单的HTML页面与脚本链接到js文件,为AI测试。如何链接或导入到我正在自己的pc上测试的wordpress站点
EN

Stack Overflow用户
提问于 2021-10-28 14:07:23
回答 1查看 33关注 0票数 0

下面是取自tensorflow示例的简单HTML代码。我已经在我自己的pc上创建了一个wordpress站点,只是为了测试,我想将页面或页面的内容添加到该网站。两种方式:第一种是首选方式,尝试将HTML代码和js文件(包含tensorflow命令,与主题无关)集成到wordpress页面中。HTML没有问题,但是我找不到链接js文件的方法。我尝试过使用wp_enqueue_script修改function.php,但是我不知道在哪里存储js文件,也不知道要指定的路径。如果它在预览中起作用,当我公开页面时它就不起作用了。还有一些其他的方法都没有成功。第二种方法是链接旧的html页面,但是我应该在哪里插入html文件和js文件呢?

谢谢你的帮助,我真的卡住了。

代码语言:javascript
复制
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"> </script>
<script src="webcam.js"></script>
<script src="rps-dataset.js"></script>
</head>
<body>
    <div>
        <div>
            <video autoplay playsinline muted id="wc" width="224" height="224"></video>
        </div>
    </div>
    <button type="button" id="0" onclick="handleButton(this)" >Rock</button>
    <button type="button" id="1" onclick="handleButton(this)" >Paper</button>
    <button type="button" id="2" onclick="handleButton(this)" >Scissors</button>
    <div id="rocksamples">Rock Samples:</div>
    <div id="papersamples">Paper Samples:</div>
    <div id="scissorssamples">Scissors Samples:</div>
    <button type="button" id="train" onclick="doTraining()" >Train Network</button>
    <div id="dummy">Once training is complete, click 'Start Predicting' to see predictions, and 'Stop Predicting' to end</div>
    <button type="button" id="startPredicting" onclick="startPredicting()" >Start Predicting</button>
    <button type="button" id="stopPredicting" onclick="stopPredicting()" >Stop Predicting</button>
    <div id="prediction"></div>
</body>

<script src="index.js"></script>
</html>
EN

回答 1

Stack Overflow用户

发布于 2021-10-29 17:25:16

我想最好的方法是创建一个定制的页面模板。

您使用的是自定义主题还是来自wordpress主题存储库中的主题?我在问,因为后者将经常更新,并覆盖自定义选项,如您的functions.php中的那些。在这种情况下,您可以创建子主题。

请参阅此描述:Create Child Themes

然后,您可以通过创建一个新文件来创建自定义页面模板,如

主题/子主题文件夹中的"page-tmpl-tensor.php“。

它的内容实际上非常接近您的html代码,但它需要一些wordpress特定的函数/变量才能工作

代码语言:javascript
复制
<?php 
/* 
   Template name: tensorflow 
   Template Post Type: post, page
*/ 
$theme_url = get_template_directory_uri();
?> 
<html>
<head>
<link rel="stylesheet" href="<?php echo $theme_url; ?>/tensor.css">
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"> </script>
<script src="<?php echo $theme_url; ?>/webcam.js"></script>
<script src="<?php echo $theme_url; ?>/rps-dataset.js"></script>
</head>
<body>
    <div>
        <div>
            <video autoplay playsinline muted id="wc" width="224" height="224"></video>
        </div>
    </div>
    <button type="button" id="0" onclick="handleButton(this)" >Rock</button>
    <button type="button" id="1" onclick="handleButton(this)" >Paper</button>
    <button type="button" id="2" onclick="handleButton(this)" >Scissors</button>
    <div id="rocksamples">Rock Samples:</div>
    <div id="papersamples">Paper Samples:</div>
    <div id="scissorssamples">Scissors Samples:</div>
    <button type="button" id="train" onclick="doTraining()" >Train Network</button>
    <div id="dummy">Once training is complete, click 'Start Predicting' to see predictions, and 'Stop Predicting' to end</div>
    <button type="button" id="startPredicting" onclick="startPredicting()" >Start Predicting</button>
    <button type="button" id="stopPredicting" onclick="stopPredicting()" >Stop Predicting</button>
    <div id="prediction"></div>
</body>

<?php wp_footer(); ?>
<script src="<?php echo $theme_url; ?>/index.js"></script>
</html>
<!-- tensorflow -->

您现在可以在wordpress管理区域中创建一个新页面,并且应该在页面模板下拉列表中看到您的模板"tensorflow“。

您还可以使用以下行替换正文内容,以动态检索内容:

代码语言:javascript
复制
    <?php 
    setup_postdata($post->ID);  
    echo get_the_content(); 
    ?>

现在,您可以在页面的content字段中粘贴和编辑body html。在这种情况下,请确保以html/text模式粘贴html。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69755613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档