如何使用post_id wordpress创建图像名称


How to make image name with post_id wordpress

我有一个项目可以自动制作每个帖子id的图像所以我必须保存与每个帖子相关联的每个分离的图像,并且图像名称应该是post-id我尝试了这些方法,但没有成功

wp-content/uploads/2014/<?php the_ID(); ?>.png

====================================

$id = get_the_ID();

然后

file_put_contents('wp-content/uploads/2014/text-$id.png', $image);

所以我需要一个php方法来保存在行中带有post-id的图像

file_put_contents('wp-content/uploads/2014/IMAGENAMEPOSTIDHERE.png', $image);

感谢

如果$image已经很好了,那么只需简单地使用串联或使用双引号即可使用该ID:

file_put_contents('wp-content/uploads/2014/text-$id.png', $image);
// you're using single quotes, variables will not be interpolated

任一:

$id = get_the_ID();
file_put_contents('wp-content/uploads/2014/text-'.$id.'.png', $image);

file_put_contents("wp-content/uploads/2014/text-$id.png", $image);

注意:假设您拥有适当的权限