jQuery Slideshow 循环插件反斜杠错误
我正在帮助一位朋友处理她从 Theme Forest 购买的自定义 WordPress 主题,该主题具有使用循环插件的 jQuery 幻灯片。它在所有页面上都运行良好。我查看了代码,我唯一能弄清楚的是,在博客页面上,它通过在所有 " 和 ' 字符前面添加反斜杠来错误地处理代码,这会在 javascript 中破坏它。我不确定从哪里开始解决这个问题 page.php 和 single.php 文件都引用以下代码:
<div id="slide">
<?php
if ( get_post_meta($post->ID,'head', true) ) {
echo get_post_meta($post->ID,'head', true);
} elseif ( get_post_meta($post->post_parent,'head', true) ) {
echo get_post_meta($post->post_parent,'head', true);
} else {
echo get_option('retro_headimage');
}
?>
</div>
<script type="text/javascript">
$('#slide').cycle('fade');
</script>
输出如下:
<div id="slide">
<img src="/wp-content/uploads/2009/11/over-the-hill.jpg" alt="" />
</div>
<script type="text/javascript">
$('#slide').cycle('fade');
</script>
在没有设置“head”的 post_meta 的帖子页面上,这是输出的 html :
<div id="slide">
<img src=\"/wp-content/uploads/2009/11/over-the-hill.jpg\" alt=\"\" />
</div>
<script type="text/javascript">
$('#slide').cycle('fade');
</script>
这破坏了 javascript。所以我注意到它正在回显在仪表板的“主题选项”页面中设置的“retro_headimage”选项。问题是,每当您进入“主题选项”页面并重新输入正确的代码时。对于保存后的图像,反斜杠会重新出现。有人可以帮忙吗?
I'm helping a friend with a custom WordPress theme she purchased from Theme Forest that has a jQuery slideshow using the cycle plugin. It works just fine on all the Pages. I looked at the code and the only thing I can figure out is that on the blog pages it processes the code incorrectly by adding a backslash in front of all the " and ' characters, which breaks it in the javascript. I'm not sure where to begin to fix this. Both the page.php and the single.php file reference the following code:
<div id="slide">
<?php
if ( get_post_meta($post->ID,'head', true) ) {
echo get_post_meta($post->ID,'head', true);
} elseif ( get_post_meta($post->post_parent,'head', true) ) {
echo get_post_meta($post->post_parent,'head', true);
} else {
echo get_option('retro_headimage');
}
?>
</div>
<script type="text/javascript">
$('#slide').cycle('fade');
</script>
Which is outputted like:
<div id="slide">
<img src="/wp-content/uploads/2009/11/over-the-hill.jpg" alt="" />
</div>
<script type="text/javascript">
$('#slide').cycle('fade');
</script>
On the post pages that don't have the post_meta of 'head' set, this is the outputted html:
<div id="slide">
<img src=\"/wp-content/uploads/2009/11/over-the-hill.jpg\" alt=\"\" />
</div>
<script type="text/javascript">
$('#slide').cycle('fade');
</script>
Which breaks the javascript. So I noticed that it was echoing an option of 'retro_headimage' which is set in the Theme Options page in the dashboard. The problem is, anytime you go into that Theme Options page and re-enter the correct code for the image upon saving it the backslashes reappear. Can anybody help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有使用过 PHP,但看起来主题选项页面调用了 add_option/update_option (http://codex .wordpress.org/Function_Reference/add_option),它将转义所设置的值。您需要查看是否有一种方法可以在不转义引号的情况下设置该值。
我认为这不是最终答案,希望它能为您指明正确的方向。
I have not worked on PHP but it looks like the Theme Options page calls add_option/update_option (http://codex.wordpress.org/Function_Reference/add_option) which will escape the value being set. You need to see if there is a way to set the value without escaping the quotes.
Thought it is not the final answer, hope it points you in the right direction.
我已经回答了我自己的问题,而且很简单!我没有通过自定义主题管理页面和编辑功能并弄清楚如何在不转义引号的情况下设置值,而是编辑了上面的第一个文件,并更改了“echo get_option('retro_headimage');”部分来回显基本图像标签。问题解决了! :)
I've answered my own question and it was SIMPLE! Instead of going thru custom theme admin pages and editing functions and figuring out how to set values without escaping quotes, I just edited the first file above, and changed the "echo get_option('retro_headimage');" section to echo a basic image tag. Problem solved! :)