我遇到的问题是,我无法确定声明图像alt标签的确切缺失。网站页面发布在这里 -
我也在发布模板的代码。如果你可以帮助解决这个问题,那真的很棒。请在此处查看代码:
<?php
/**
* Template Name: Blog
*
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
get_header();
?>
<?php
$page_id = $wp_query->post->ID;
?>
<div id="bd">
<div class="blog-sec">
<div class="container blog-main">
<h2>Blog</h2>
<div class="blog_left">
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts' => 1
);
$my_query = null;
$my_query = new WP_Query($args);
if ($my_query->have_posts()) {
while ($my_query->have_posts()):
$my_query->the_post();
$feat_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
?>
<div class="blog_blocks">
<div class="blog_thumb"><a href="<?php
echo get_permalink();
?>" ><img src="<?php
echo $feat_image;
?>" alt=""></a></div>
<div class="blog_content">
<h5><a href="<?php
echo get_permalink();
?>" ><?php
the_title();
?></a></h5>
<?php
$content = substr(get_the_content(), 0, 115) . "...";
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
?>
<a href="<?php
echo get_permalink();
?>" class="readmore">
<?php
if (get_bloginfo('language') === "en-US") {
echo get_option('of_blogtext_eng');
} else {
echo get_option('of_blogtext_french');
}
?>
</a>
</div>
</div>
<?php
endwhile;
}
?>
</div>
<div class="blog_right">
<?php
if (is_active_sidebar('blog')):
?>
<?php
dynamic_sidebar('blog');
?>
<?php
endif;
?>
</div>
<div class="clear"></div>
</div>
</div>
</div>
<?php
get_footer();
?>
请让我知道我需要将哪些元素添加到数组中,或者声明Image变量并在ALT标记之间写一个echo语句。
答案 0 :(得分:0)
那里有一大堆代码并不是必需的:
$feat_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
<img src="<?php
echo $feat_image;
?>" alt="">
删除$feat_image
行并用
<?php if ( has_post_thumbnail() ) the_post_thumbnail(); ?>
使用the_post_thumbnail()
功能将输出必要的HTML并自动填写替代文字,前提是文本已输入媒体库中的图像帖子。
希望有所帮助