简体   繁体   English

WordPress自定义类别页面未加载javasctipt文件并给出404错误

[英]Wordpress custom category page not loading javasctipt files and giving 404 error

I have started from scratch to develop a theme, now i have a code snippet from one websites where in he is using the script like - 我从头开始开发一个主题,现在我从一个网站上获得了一个代码片段,在该网站中他正在使用脚本-

<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>

Now i when i try this in my category-{slug}.php it searches these files in the folder wordpress/category/{slug}/ 现在,当我在我的category- {slug} .php中尝试此操作时,它会在文件夹wordpress / category / {slug} /中搜索这些文件

Now i also tried here ` 现在我也在这里尝试过`

<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>

Then also i get a 404 error in firebug but when i try something like this - 然后我在萤火虫中也遇到了404错误,但是当我尝试这样的操作时-

{jquery : "../../wp-content/themes/testing/js/literature"},

It works, Now i wanted to know that why it is looking these dependancies in the folder category rather than my theme directory whereas at the same time if i wrote these lines 它起作用了,现在我想知道为什么它在文件夹类别而不是主题目录中查找这些依赖关系,而同时如果我写这些行

<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/literature/head.min.js"></script>

in my head section and to my surprise they work, can anyone tell me what is going on here 在我的脑海中,让我惊讶的是,它们起作用了,谁能告诉我这是怎么回事

Accordingly to your code, you're using a script called head.js , which allows you to add more scripts to your header. 根据您的代码,您正在使用一个名为head.js的脚本,该脚本允许您向标头添加更多脚本。 If you truly want to use head.js, you have to add that script in your head manually. 如果您确实要使用head.js,则必须手动将该脚本添加到头部。 I discourage using what you don't really need. 我不鼓励使用您真正不需要的东西。

Put this PHP code in your functions.php file, which should be located in your theme directory. 将此PHP代码放入您的functions.php文件中,该文件应该位于主题目录中。 If not, create it. 如果没有,请创建它。 This is how you usually include scripts to your theme. 这通常是将脚本包含到主题中的方式。

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'));
}

PS. PS。 Don't forget that PHP code always starts with <?php 不要忘记PHP代码始终以<?php开头

在加载category- {slug} .php之前先加载wp-blog-header.php吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM