【发布时间】:2012-05-07 18:27:43
【问题描述】:
如果我这样调用帖子,每个帖子都包含许多图像,是否有任何 PHP 可以用来查找每个帖子中所有图像的总宽度,然后将 div id="page" 设置为最厉害的?
<div id="page">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content">
<?php the_content(); ?>
</div><!-- .entry-content -->
</div><!-- #post-## -->
</div>
在 javascript 中很容易,我是 PHP 新手,但怀疑它是可行的? 干杯!
【问题讨论】:
-
你是把图片的宽度存储在数据库里还是什么的?
-
getImageSize() 可能对你有用。 us3.php.net/manual/en/function.getimagesize.php
-
这对我来说似乎有点倒退...为什么不尝试将图像限制为适合您的内容 div 的设置大小?一行css应该可以解决问题。另外,是的,使用 js 很容易做到这一点。
标签: php image wordpress html width