长篇故事我使用的是WordPress和Zurb Foundation附带的轨道滑块。我很快发现了一个使用Orbit Slider的WordPress插件,除了它没有使用alt=""
这个我热衷于修复的事实之外,它工作得很好。我不是WordPress codex和php中最好的人,但是我已经给它了。
我添加了以下get_post_meta数据:
$imgalt = get_post_meta( $imgid->ID, '_wp_attachment_image_alt', true );
它应该感觉来自的alt标签信息
$imgid = get_post_thumbnail_id();
我稍后使用以下方法调用此数据:
echo `'<img class="orbit-slide" src="' . $urlimg . '" alt="' . $imgalt .'" />';`
但遗憾的是,我和alt=""
我会添加完整的代码,以便您更多地了解我尝试改编的内容:
<?php foreach($slider_posts as $post): setup_postdata($post);
$options = $this->get_options();
// Get the title
$title = get_the_title();
// Get the excerpt
$excerpt = get_the_excerpt();
// Fetch image for slider
$imgsize = $options->imgSize;
$img = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ''.$imgsize.'' ); $urlimg = $img['0'];
// Fetch image ID (then applied to content divs for styling individual content areas)
$imgid = get_post_thumbnail_id();
// Get image alt
$imgalt = get_post_meta( $imgid->ID, '_wp_attachment_image_alt', true );
// Fetch thumbnail for slider
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'orbit-slide-small' ); $urlthumb = $thumb['0'];
// Slide Caption
$caption = get_post_meta($post->ID, '_sliderCaption', TRUE);
// Target exists?
$target = get_post_meta($post->ID, '_sliderTarget', TRUE);
// If so, target URL
$link = get_post_meta($post->ID, '_sliderUrl', TRUE);
// If alt used lets init alt tag
if( $caption == TRUE ) {
$datacaption = 'data-caption="#slide-' . get_the_ID() . '"';
} else {
$datacaption = '';
}
// Output the thumbnail
$datathumb = 'data-thumb="' . $urlthumb . '"';
// If slide has target
if( $link == TRUE ) {
echo '<a target="' . $target . '" href="' . $link . '"' . $datacaption . $datathumb . '><img class="orbit-slide" alt="' . $imgalt .'" src="' . $urlimg . '" /></a>';
// If not and has html content
} elseif( !empty($post->post_content) ) {
echo '<div class="content" style=""' . $datathumb . '>';
echo '<div class="slide-content slide-content-' . $imgid . '">' . get_the_content() . '</div>';
echo '<img class="orbit-slide" src="' . $urlimg . '" alt="' . $imgalt .'" />';
echo '</div>';
// Otherwise, lets just use images
} else {
echo '<img class="orbit-slide" src="' . $urlimg . '"' . $datacaption . $datathumb . ' alt="' . $imgalt .'"/>';
}
endforeach; ?>
答案 0 :(得分:0)
这是你的代码:
$imgid = get_post_thumbnail_id();
// Get image alt
$imgalt = get_post_meta( $imgid->ID, '_wp_attachment_image_alt', true );
get_post_thumbnail_id()会返回一个ID,因此$imgid
应该包含它。因此,您应该在$imgid
内使用$imgid->ID
而不是get_post_meta()
。试试这个:
$imgalt = get_post_meta( $imgid, '_wp_attachment_image_alt', true );