您能否请看一下这段代码,让我知道为什么我在
中输出alt
属性
echo '<img src="'.wp_get_attachment_link($image, 'large').'" alt="Projects" />';
在以下代码段中:
$images = get_post_meta($post->ID, 'vdw_gallery_id', true);
foreach ($images as $image) {
echo '<div class="col-xs-6 col-md-3">';
echo '<div class="thumbnail">';
echo '<img src="'.wp_get_attachment_link($image, 'large').'" alt="Projects" />';
echo '</div>';
echo '</div>';
}
这是发生的事情
答案 0 :(得分:5)
wp_get_attachment_link
会返回html link
https://codex.wordpress.org/Function_Reference/wp_get_attachment_link
使用wp_get_attachment_image_src
代替https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/
$images = get_post_meta($post->ID, 'vdw_gallery_id', true);
foreach ($images as $image) { ?>
<div class="col-xs-6 col-md-3">
<div class="thumbnail">
<?php
$img = wp_get_attachment_image_src($image,'large');
if ($img && isset($img[0])):
?>
<img src="<?php echo $img[0];?>" alt="Projects" />
<?php endif;?>
</div>
</div>
<?php }?>
答案 1 :(得分:0)
试试这个
echo "<img src='".wp_get_attachment_image_src($image,'large')."' alt='Projects'/>";
答案 2 :(得分:0)
此行中的错误
'
您的错误归因于'large'
中的$images = get_post_meta($post->ID, 'vdw_gallery_id', true);
foreach ($images as $image) {?>
<div class="col-xs-6 col-md-3">
<div class="thumbnail">
<img src="<?=wp_get_attachment_link($image, 'large')?>" alt="Projects" />
</div>
</div>
<?php }?>
更改为
var session = require('express-session');
app.use(session({secret: 'keyboard cat', resave: false, saveUninitialized: true,cookie: { path: '/', httpOnly: true, maxAge: 30 * 30000 },rolling: true}));
router.post('/savesession', function (req, res) {
req.session.user = 'user';
req.session.save()
res.json(req.session.user);
});
router.get('/getsession', function (req, res) {
res.json(req.session.user);
});