Php 获取特定Div的宽度,然后显示以下代码
我现在被困在这种情况下 我有3个大小不同的帖子缩略图 根据用户屏幕的大小,我只需要显示一个图像。我不喜欢使用css媒体查询或通过css调整同一图像的大小,因为它会失真。无论如何,如果,它是否可以用PHP实现 比如: 如果blogpost width==360px 显示Php 获取特定Div的宽度,然后显示以下代码,php,wordpress,Php,Wordpress,我现在被困在这种情况下 我有3个大小不同的帖子缩略图 根据用户屏幕的大小,我只需要显示一个图像。我不喜欢使用css媒体查询或通过css调整同一图像的大小,因为它会失真。无论如何,如果,它是否可以用PHP实现 比如: 如果blogpost width==360px 显示 否则,如果.blogpost宽度==300px 显示 否则,如果.blogpost宽度==250px 显示 这是html结构: <div class="blogpost" id="blogpost"> <a c
否则,如果.blogpost宽度==300px
显示
否则,如果.blogpost宽度==250px
显示
这是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>
您可以尝试类似的方法 (请注意,如果您启用了pretty permalink,请确保您使用这一行,只需将第一行更改为(&to) document.location=\“$url?r=1&width=\”+screen.width+\“&Height=\”+screen.Height)
您需要javascript来获取浏览器的尺寸。你可以在Ajax发送用户的视口大小之后加载你的内容,但是这个解决方案嗅到你可以发送一个缩略图<代码>宽度>代码>一个<代码>获取参数并使用它。如果分辨率改变,图像也不会改变(浏览器的大小调整)。
<?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
}
}
?>