我和Smarty一起工作.我想if else在我的.tpl文件中为n-child li/div类添加一个条件.
我有两个图像尺寸.我想在第一个中使用600px图像,li在第二个和第三个中使用400px图像,在第4个中再使用600px图像li,依此类推.
目前我正在使用CSS3 nth-child选择器并使用缩放的400px图像.但是加载时间很糟糕.我想在需要的地方使用较小的图像.
我猜它非常复杂.是吗?
这是我的代码:
<img src="{$purl}/thumbs/{$posts[i].pic}" alt="{$posts[i].story|stripslashes}" />
Run Code Online (Sandbox Code Playgroud)
它存在于循环{section name=i loop=$posts} {include file="posts.tpl"} {/section}内部posts.tpl.
我正在使用 PHP 简单的 HTML DOM,刚刚发现它无法从data-src属性或<img src没有 http 的情况下读取图像:例如;<img src="//static.mysite.com/123.jpg">
有没有办法让它发生?
我的代码是:
if($htm->find('img')){
foreach($htm->find('img') as $element) {
$raw = file_get_contents_curl($element->src);
$im = @imagecreatefromstring($raw);
$width = @imagesx($im);
$height = @imagesy($im);
if($width>500&&$height>=350){
$hasimg = '1';
echo '<img src=\'' .$element->src. '\'>';
}
} // end foreach
} // end if htm
Run Code Online (Sandbox Code Playgroud)