php - 如何捕获特色图像的宽度和高度值 (Php)
问题描述
在 wordpress 中,添加到主题的第一张图片是我的特色图片我将此代码添加到 function.php 出于这个原因
// picture
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
if(preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches)){
$first_img = $matches [1] [0];
return $first_img;
}
else {
$first_img = get_template_directory_uri()."/images/default.jpg";
return $first_img;
}
}
//picture
我在 content.php 中添加了以下代码
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail('large');
} else {
echo '<img src="';
echo catch_that_image();
echo '" alt="'.get_the_title().'" title="'.get_the_title().'"/>';
} ?>
但是我的特色图片中没有宽度和高度值(谷歌已经警告过我),我怎样才能自动获取特色图片的宽度和高度值?
解决方案
推荐阅读
- database - 无法读取数据 - option() 获得了意外的关键字参数“sfUrl”
- android - 检索我从 Windows 桌面手动复制到手机/模拟器的图像
- python - IMAP 电子邮件 IDLE 停止等待超时时间,而是在 Python 中立即循环
- python - 使用python过滤频率
- c++ - 如何在 C++ 20 中执行链式协程
- react-native - 反应本机应用程序中的bitcore-wallet-client
- xml - XSLT:使用 XSLT 1.0 规范化与 complexTypes 的 XML 关系
- r - 编写一个 for 循环以在 R 中生成制表符分隔的文件
- mysql - 我可以在添加了变量值的列上利用索引吗?
- git - 为什么 'git config --list' 显示两个电子邮件地址和一个用户名?