我正在使用Wordpress中的jQuery Nivo Slider插件(但不是同名的Wordpress插件)和自定义帖子,它工作得很完美而且很简单,除了将网站根添加到图像路径之外。我正在为我的形象拉开一条绝对的道路
http://www.site.com/images/image.jpg
但Nivo正在将站点根目录添加到路径中,该路径生成:
www.site.com/http://www.site.com/images/image.jpg
我在Nivo的文档中找不到一个选项来设置它采取绝对路径...任何想法?
这是我的模板代码:
<?php global $post;
$myposts = get_posts('post_type=homepageslider&numberposts=4&order=asc');
foreach($myposts as $post) :
setup_postdata($post);?>
<a href="<?php the_field('link'); ?>"><img src="<?php the_field('image'); ?>" data-thumb="<?php the_field('image'); ?>" /></a>
<?php endforeach; ?>
一些评论:
以下是浏览器中呈现的HTML。如您所见,“当前幻灯片”路径很好。问题在于nivo-slice div中的内容:它为它们添加了额外的根。这是我在使用插件时没有任何自定义帖子或字段时遇到的相同问题。
<a class="nivo-imageLink" href="http://www.mysite.com/products/product1/" style="display: none;">
<a class="nivo-imageLink" href="http://www.mysite.com/products/product2/" style="display: none;">
<a class="nivo-imageLink" href="http://www.mysite.com/products/product3/" style="display: none;">
<a class="nivo-imageLink" href="http://www.mysite.com/products/product4/" style="display: block;">
<img class="nivo-main-image" src="http://www.mysite.com/wp-content/uploads/product1.jpg" style="display: inline; height: 377px;">
<div class="nivo-caption"></div>
<div class="nivo-slice" name="0" style="left: 0px; width: 971px; height: 377px; opacity: 1; overflow: hidden;">
<img style="position:absolute; width:971px; height:auto; display:block !important; top:0; left:-0px;" src="www.mysite.com/http://www.mysite.com/wp-content/uploads/product1.jpg">
</div>
(并且使用不同的幻灯片重复div -ivo-slice [名称从0到14])
以下是控制台中生成的错误(每次滑块旋转时重复)
GET http://www.mysite.com/http:/www.mysite.com/wp-content/uploads/product1.jpg 404 (Not Found) /http:/www.mysite.com/wp-content/uploads/product1.jpg:1
GET http://www.mysite.com/http:/www.mysite.com/wp-content/uploads/product.jpg 404 (Not Found)
另一个更新:我完全取出了wordpress循环并输入了4个静态图像链接。旋转器工作正常,显示图像正常,但具有相同的问题,损坏的图像图标,并将网站URL添加到现有路径。
答案 0 :(得分:0)
在插件中,您可以指定绝对路径。 Wordpress已经内置了以下代码:
$wpDir = ABSPATH;
print_r($wpDir) // path to wp install
您可以看到显示内容,然后相应地调整图像路径。
答案 1 :(得分:0)
线索在您收到的404错误消息中。
http:/www.mysite.com/wp-content/uploads/product1.jpg
由于该方案缺少额外的正斜杠,因此URL格式不正确,我想这会被解释为相对URL。