我现在被困在这种情况下。
我有3个帖子缩略图不同尺寸。
我需要根据用户屏幕的大小只显示一个图像。我不喜欢使用CSS媒体查询或通过CSS调整相同的图像,因为它变得扭曲。无论如何,是否有可能实现 PHP IF ?
类似的东西:
IF blogpost width == 360px
显示<?php the_post_thumbnail('post-thumbnails2200px', array( 'id' => "FeatureImage")); ?>
否则如果.blogpost width == 300px
显示<?php the_post_thumbnail('post-thumbnails1280px', array( 'id' => "FeatureImage")); ?>
否则,如果.blogpost width == 250px
显示<?php the_post_thumbnail('post-thumbnails600px', array( 'id' => "FeatureImage")); ?>
这是html结构:
<div class="blogpost" id="blogpost">
<a class="post_title" href="<?php the_permalink() ?>" rel="bookmark" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail('post-thumbnails2200px', array( 'id' => "FeatureImage")); ?>
</a>
</div>
答案 0 :(得分:0)
document.location = \ “$网址R = 1和;宽度= \” + screen.width + \ “&安培;身高= \” + screen.height)
<?php
// Get the current page
$url = get_permalink($post->ID);
if(!isset($_GET['r']))
{
echo "<script language=\"JavaScript\">
<!--
document.location=\"$url&r=1&width=\"+screen.width+\"&Height=\"+screen.height;
//-->
</script>";
}
else {
// Code to be displayed if resolutoin is detected
if(isset($_GET['width']) && isset($_GET['Height'])) {
// Resolution detected
$blogpost_width = $_GET['width'];
}
else {
// Resolution not detected
}
}
?>