我有一个问题,那就是我不能确定声明图像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 variable并在它们之间为ALT标记编写一个echo语句。
发布于 2018-02-01 21:15:31
有一整块代码实际上并不是必需的:
$feat_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
<img src="<?php
echo $feat_image;
?>" alt="">删除$feat_image行并将第2位替换为
<?php if ( has_post_thumbnail() ) the_post_thumbnail(); ?>
使用the_post_thumbnail()函数将输出必要的超文本标记语言,并自动填充alt文本,当然前提是文本已输入到媒体库中的图像帖子中。
希望这能有所帮助
https://stackoverflow.com/questions/48563345
复制相似问题