【问题标题】:Wordpress print_thumbnail not giving correct urlWordpress print_thumbnail 没有给出正确的网址
【发布时间】:2012-03-13 14:39:08
【问题描述】:

我一直很难解决这个问题。 我在 Ubuntu Server 64bit 上运行 Wordpress 3.3.1

所以我可以上传一张图片并使用提供的网址查看它。 但是,当我将其设置为特征图像时,该功能似乎 print_thumbnail 没有给我正确的地址。 它在我的 /wp-content/uploads/etc 之前添加 /var/www/... 因此,借助一些符号链接,我的机器上的绝对路径名将是正确的。

我尝试更改文件上的 css 以删除 /var/www/ 并验证这确实找到了我的图像并且有效。我已经看到很多帖子告诉我将 chmod 777 更改为 755,如 wp print_thumbnail function is not workinghttps://stackoverflow.com/questions/9003277/wp-print-thumbnail-function-not-working-correctly 我不知道这是如何解决问题的,因为这似乎是一个路径问题。是否有某种基于权限的重定向?无论如何,它没有工作。

有人有什么想法吗?

这是一个示例帖子 http://mobile.cs.fsu.edu/google-chrome-app-on-android-market/

【问题讨论】:

    标签: php apache wordpress


    【解决方案1】:

    你可以试试这个而不是print_thumbnail

    <?php
    if ( has_post_thumbnail() ) {
        the_post_thumbnail(); // Outputs <img/> object with src="thumbnail-href"
    }
    

    同样,这也可以:

    <?php
    if ( has_post_thumbnail() ) {
        echo( get_the_post_thumbnail( get_the_ID() ) );
    }
    

    如果您在 functions.php 中设置了多个特色图像大小......

    <?php
    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 120, 120 );
    add_image_size( 'subfeature', 940, 300 );
    

    您可以通过这种方式引用大小(其中subfeature 是大小的名称):

    <?php
    if ( has_post_thumbnail() ) {
        echo( get_the_post_thumbnail( get_the_ID(), 'subfeature' ) );
    }
    

    【讨论】:

      【解决方案2】:

      在函数中我发现它使用get_bloginfo函数来打印样式表目录

      $output = '<img src="'.get_bloginfo('stylesheet_directory').'/timthumb.php?src='.$thumbnail.'&amp;h='. $height .'&amp;w='. $width .'&amp;zc=1"';
      

      wordpress codex of get_bloginfo 中,它说:

      'stylesheet_directory' - 返回样式表目录的 URL 活跃的主题。 (在早期的 WordPress 版本中是本地路径。) 考虑改用get_stylesheet_directory_uri()

      将 get_bloginfo('stylesheet_directory') 更改为 get_stylesheet_directory_uri()
      我自己没试过,希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 2014-05-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多