0

wordpress サイトで、timthumb 構成ファイルにデフォルトの NOT_FOUND_IMAGE を定義しました。

// "http://example.com/timthumb-config.php".
<?php 
if(! defined('NOT_FOUND_IMAGE') ) define ('NOT_FOUND_IMAGE', 'http://example.com/img/default.jpg');

timthumb リクエスト パラメータに応じて、この画像のサイズを強制的に変更する方法はありますか。例えば:

// 404 occurs
timthumb.php?src=http:%2F%2Fexample.com%2Fimg%2F404-image.jpg&h=180&w=120
// get resized (cropped) default image
timthumb.php?src=http:%2F%2Fexample.com%2Fimg%2Fdefault.jpg&h=180&w=120 
4

2 に答える 2

1

このコードを試してください:

if (!defined('NOT_FOUND_IMAGE'))
  define ('NOT_FOUND_IMAGE','images/ingredient.jpg');
于 2016-01-30T05:00:03.483 に答える
0

を評価しませんtimbthumb。セキュリティ上の問題があると思います。代わりにThumbGen プラグインをインストールして使用してください。

その後、通常の編集可能な条件付きphpステートメントで非常に簡単に使用できます..(疑似)

<?php if you have a thumbnail { 
       Output the img with thumbgen resized
} else {
       Output the no image, you can even use thumbgen if you want
}
?>

実際の例:

<?php if ( has_post_thumbnail() )
        {
        $image_id = get_post_thumbnail_id();
        $alt_text = get_post_meta($image_id, '_wp_attachment_image_alt', true);
        $image_url = wp_get_attachment_image_src($image_id,'large');  
        $image_url = $image_url[0];
        ?>

            <img src='<?php thumbGen($image_url,175,175, "crop=1"); ?>' />

        <?php
        }

    else
        {
        ?>

            <img src="<?php bloginfo('template_url');?>/images/no-photo.png" alt="No Photo!">

        <?php
        }
?>
于 2012-08-24T12:13:33.183 に答える