【发布时间】:2014-03-23 14:53:17
【问题描述】:
如何在 wordpress 中检索和显示图像的替代文本?试图用标题代替 alt。这是原始代码。
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
所以在我想要的 h1 中:
<h1 class="entry-title">"alt text of image"</h1>
试着把它放在一个像这样的变量中:
$alt_text = get_post_meta($img_id , '_wp_attachment_image_alt', true);
<h1 class="entry-title"><?php echo $alt_text; ?></h1>
但它没有显示出来。有什么解决办法吗?
【问题讨论】:
-
当前输出是多少?你确定变量
$img_id是正确的吗? -
当前输出什么都不是。不知道 $img_id 是否正确。