WordPress 固定链接
我将我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在模板文件中引用任何内容,则可以使用
1:
或 2: ,
这将被编码为:
或
1: 加载主站点 URL;
2:将返回当前主题目录的绝对url
(这更有利于主题开发)。
if you are referencing anything in your template files you can use either
1:
or 2:
which would be coded as:
or
1: loaded the main site URL;
2: will return the absolute url to your current themes directory,
(which is better for theme development).
我猜你正在手动插入 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).