WordPress自定义类别页面未加载javasctipt文件并给出404错误
Wordpress custom category page not loading javasctipt files and giving 404 error
我从头开始开发一个主题,现在我有一个来自一个网站的代码片段,其中他正在使用这样的脚本 -
<script>
head.js(
{ jquery : "js/jquery.min.js" },
{ mousewheel : "js/jquery.mousewheel.js" },
{ mwheelIntent : "js/mwheelIntent.js" },
{ jScrollPane : "js/jquery.jscrollpane.min.js" },
{ history : "js/jquery.history.js" },
{ stringLib : "js/core.string.js" },
{ easing : "js/jquery.easing.1.3.js" },
{ smartresize : "js/jquery.smartresize.js" },
{ page : "js/jquery.page.js" }
);
</script>
现在,当我在我的类别中尝试此操作时-{slug}.php它会在文件夹中搜索这些文件 wordpress/category/{slug}/
现在我也在这里尝试了"
<script>
head.js(
{ jquery : "<?php bloginfo('template_url')?>/js/jquery.min.js" },
{ mousewheel : "<?php bloginfo('template_url')?>/js/jquery.mousewheel.js" },
{ mwheelIntent : "<?php bloginfo('template_url')?>/js/mwheelIntent.js" },
{ jScrollPane : "<?php bloginfo('template_url')?>/js/jquery.jscrollpane.min.js" },
{ history : "<?php bloginfo('template_url')?>/js/jquery.history.js" },
{ stringLib : "<?php bloginfo('template_url')?>/js/core.string.js" },
{ easing : "js/jquery.easing.1.3.js" },
{ smartresize : "<?php bloginfo('template_url')?>/js/jquery.smartresize.js" },
{ page : "<?php bloginfo('template_url')?>/js/jquery.page.js" }
);`
</script>
然后我也在火虫中收到 404 错误,但是当我尝试这样的事情时 -
{jquery : "../../wp-content/themes/testing/js/literature"},
它有效,现在我想知道为什么它在文件夹类别而不是我的主题目录中查找这些依赖项,而同时如果我写了这些行
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/literature/head.min.js"></script>
在我的脑海部分,令我惊讶的是它们工作,谁能告诉我这里发生了什么
根据你的代码,你正在使用一个名为head.js的脚本,它允许你向标头添加更多脚本。如果你真的想使用 head.js,你必须手动在脑海中添加该脚本。我不鼓励使用你并不真正需要的东西。
把这个PHP代码放在你的函数.php文件中,该文件应该位于你的主题目录中。如果没有,请创建它。这就是您通常将脚本包含在主题中的方式。
add_action('wp_enqueue_scripts', 'mytheme_enqueue_scripts');
function mytheme_enqueue_scripts() {
// jQuery comes with WordPress, no need to include it
$dir = get_stylesheet_directory_uri() . '/js';
// Vanilla scripts
wp_enqueue_scripts('stringLib', $dir . '/core.string.js');
// All these guys depend on jQuery, hence the "array('jquery')"
wp_enqueue_scripts('easing', $dir . '/jquery.easing.1.3.js', array('jquery'));
wp_enqueue_scripts('easing', $dir . '/jquery.smartresize.js', array('jquery'));
wp_enqueue_scripts('easing', $dir . '/jquery.page.js', array('jquery'));
wp_enqueue_scripts('history', $dir . '/jquery.history.js', array('jquery'));
wp_enqueue_scripts('mousewheel', $dir . '/jquery.mousewheel.js', array('jquery'));
wp_enqueue_scripts('mwheelintent', $dir . '/jquery.easing.1.3.js', array('jquery'));
wp_enqueue_scripts('mwheelintent', $dir . '/mwheelIntent.js', array('jquery'));
wp_enqueue_scripts('jscrollpane', $dir . '/jquery.jscrollpane.min.js', array('jquery'));
// This one happens to rely on jScrollPane
wp_enqueue_scripts('mwheelintent', $dir . '/mwheelIntent.js', array('jscrollpane'));
}
不要忘记PHP代码总是以<?php
开头
wp-blog-header.php 在加载 category-{slug}.php 之前是否加载
相关文章:
- 咕噜声.js无法读取文件(错误代码:EISDIR)
- 在 ubuntu 14.04 VPS 上执行.js文件错误
- 命令代码jquery文件错误
- XMLHttpRequest无法加载Angular js中的文件错误
- 咕噜声/巴别塔错误:无法写入“dist”文件(错误代码:EISDIR)
- 未捕获的类型错误:对象[对象对象]在文件 y 错误中没有方法“x”
- angularjs + 下载 csv 文件 + 错误: [$injector:unpr] 未知提供程序
- 露天更新文件 - 错误开机自检
- Django ExtJs 6:上传文件错误
- Dropbox放入保护程序本地主机文件错误
- 我的网站在提交时出现文件错误
- php生成的JSON文件错误
- JSON文件错误
- 为什么Chrome开发者工具/控制台不显示javascript文件/错误是动态加载的
- 保存JSON文件错误
- Facebook Javascript表单数据照片上传:需要上传文件错误
- 如何在Node.js中上传文件?错误:无法POST/上载
- 外部javascript文件错误
- 使用jQuery表单插件上传文件-无效文件错误
- Json上传jquery文件错误