【问题标题】:Wrong media files url on WordPress siteWordPress 网站上错误的媒体文件 URL
【发布时间】:2016-04-20 02:16:52
【问题描述】:

我在 WordPress 网站上遇到了一个问题: 没有显示作为媒体文件上传的图像。我看到他们有这样的错误网址

<a class="thumbLink" href="http:///wp-content/uploads/2014/10/Joseph-Angharad-11.7.2014-271.jpg" rel="prettyPhoto[gallery1]" title=""><i class="icon-search"></i></a>

我尝试上传新的媒体文件,但它们获得了相似的 url,但没有显示。 在数据库中似乎没问题。我没有在其中看到这样的网址。 你遇到过这样的问题吗?在哪里寻找解决方案?

据我所知,它发生在删除插件(非活动)之前。

我通过以下代码获取图像:

// instantiate the controller
if (!function_exists("peTheme")) {
    $peThemeClassName = apply_filters('pe_theme_controller_classname','PeTheme'.PE_THEME_NAME);

    PeGlobal::$controller =& new $peThemeClassName();

    function &peTheme() {
        return PeGlobal::$controller;
    }

    peTheme()->boot();

}

<?php $t =& peTheme(); ?>

<section class="thumbImage">
    <img src="<?php echo $t->image->resizedImgUrl($content->get_origImage(),350,0); ?>" alt="" class="fullwidth">
    <div class="thumbTextWrap">
        <div class="thumbText">
            <a href="<?php echo get_permalink(); ?>"><h3 class="sectionTitle"><?php $content->title(); ?></h3></a>
    <?php 
        $text = get_the_excerpt();
            if (strlen($text) > 40)
            $text = substr($text, 0, 40) . '...';

            echo '<p>' . $text . '</p>';
    ?>

    <?php while ($slide =& $slider->next()): ?>

    <?php $img = $slide->img; ?>
    <?php
        if ( $first ) { 
    ?>
    <a class="thumbLink" href="<?php echo $img; ?>" rel="prettyPhoto['<?php $content->slug(); ?>']" title=""><i class="icon-search"></i></a>
    <?php
        $first = false;
        } else {
    ?>
    <a href="<?php echo $img; ?>" rel="prettyPhoto['<?php $content->slug(); ?>']" title=""></a>
    <?php
        }

    <?php endwhile; ?>
        </div>
    </div>
 </section>

【问题讨论】:

  • 如果你 var_dump(site_url()); 会发生什么。 href 属性中缺少 site_url。显示如何获取图像的代码。
  • 我更新了问题,请看一下
  • 您在该代码中遗漏了一些内容...$t 是什么? $t-&gt;image-&gt;resizedImgUrl 来自哪里?
  • @mevius 我添加了一些我错过的东西,但是这段代码被分成了几个文件,我不擅长 PHP,所以如果我错过了其他东西,请告诉我,我会尽力找到它。

标签: wordpress


【解决方案1】:

我很傻,但我没有禁用插件来检查。 问题出在 Parallelize 插件中。它已被禁用,从现在起媒体文件具有正确的 url。

【讨论】:

  • 那个插件很遗憾很久没有更新了。它不再起作用了!
【解决方案2】:

这篇文章可能有点过时了,但我最近遇到了一个类似的问题,所以如果它对任何人都有用:

首先,我之前更改了 Wordpress 上传目录,将以下内容添加到 wp-config.php 的末尾

define( 'UPLOADS', ''.'files' );

所以我所有的文件都保存在domain.com/files/ 升级到 Wordpress 4.5 后,所有媒体文件的 url 都非常错误,(像 .../wp-content/uploads/rootuser/public_html/wp-content/上传...)我尝试重新安装 Wordpress,再次更改目录,禁用插件,然后我发现一些关于 Search & Replace 工作的帖子,但仍然没有运气。

然后我找到了这个插件,Upload Url and Path Enabler,并使用了适合我情况的以下设置:

存储文件:files

完整文件网址:http://www.domain.com/files

然后转眼!所有媒体 URL 都神奇地更新了,一切都恢复正常了!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-26
    • 2017-03-11
    • 1970-01-01
    • 1970-01-01
    • 2018-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多