WordPress 固定链接

发布于 2024-08-25 09:49:08 字数 795 浏览 7 评论 0原文

我将我的 WordPress 永久链接结构设置为 /%postname%/ 但现在当我转到主页以外的页面时(例如,如果我转到 somelink.com/about),我会丢失所有 javascript 引用。

我认为发生这种情况是因为 js 文件的链接不再像想象的文件夹“about”中那样正确。这就是 header.php 文件中引用 js 文件的方式。

        <script type="text/javascript" src="wp-content/themes/default/js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="wp-content/themes/default/js/cufon-yui.js"></script>
    <script type="text/javascript" src="wp-content/themes/default/js/Goudy_Bookletter_1911_400.font.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {      
            Cufon.replace('h1');
            Cufon.replace('h3', {textShadow:'0 1px #fff'});
        });
    </script>

我做错了什么吗?

I set my wordpress permalink structure to /%postname%/ but now when I go to a page other than the home page (for example if I went to somelink.com/about) I lose all javascript references.

I think this happens because the links to the js files are no longer right as it is in the imaginary folder "about". This is how the js files are referenced in the header.php file.

        <script type="text/javascript" src="wp-content/themes/default/js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="wp-content/themes/default/js/cufon-yui.js"></script>
    <script type="text/javascript" src="wp-content/themes/default/js/Goudy_Bookletter_1911_400.font.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {      
            Cufon.replace('h1');
            Cufon.replace('h3', {textShadow:'0 1px #fff'});
        });
    </script>

Am I doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

惯饮孤独 2024-09-01 09:49:08

如果您在模板文件中引用任何内容,则可以使用

1:

<?php bloginfo('url');?>

或 2: ,

<?php bloginfo('template_url');?>

这将被编码为:

<script type="text/javascript" src="<?php bloginfo('url');?>/wp-content/themes/default/js/jquery-1.4.2.min.js"</script>

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

1: 加载主站点 URL;
2:将返回当前主题目录的绝对url

(这更有利于主题开发)。

if you are referencing anything in your template files you can use either

1:

<?php bloginfo('url');?>

or 2:

<?php bloginfo('template_url');?>

which would be coded as:

<script type="text/javascript" src="<?php bloginfo('url');?>/wp-content/themes/default/js/jquery-1.4.2.min.js"</script>

or

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

1: loaded the main site URL;
2: will return the absolute url to your current themes directory,

(which is better for theme development).

奢望 2024-09-01 09:49:08

我猜你正在手动插入 javascript 调用,这不是在 Wordpress 中处理 jQuery 包含的最佳方法 - 你应该查看 wp_enqueue_script,如果您使用的插件或主题也包含 jquery 库,这将阻止您多次包含它们。

另外,如果您编写了源代码,我相信您是正确的 - 客户端正在 /about 下的相对路径中查找 js 文件。在 wp-content 之前放置一个“/”,让客户端在根目录下的 wp-content 中查找它们(假设 WP 安装在根目录下)。

I gather you are manually inserting the javascript calls, which is not the best way to handle jQuery inclusion in Wordpress - you should look into wp_enqueue_script, which will keep you from including the jquery libraries more than once if a plugin or theme you are using is also including them.

Also, the ay you have the source written, I believe you are correct - the client is looking for the js files in the relative path under /about. Place a "/" before wp-content to have the client look for them inside wp-content within your root directory (assuming WP is installed at root).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文