首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WordPress图像的Alt标签为空

WordPress图像的Alt标签为空
EN

Stack Overflow用户
提问于 2018-02-01 20:58:18
回答 1查看 488关注 0票数 2

我有一个问题,那就是我不能确定声明图像alt标记到底缺少了什么。网站页面张贴在这里-

https://www.njoyn.com/blog/

我还发布了该模板的代码。如果你能帮我解决这个问题,那就太好了。请在此处检查代码:

代码语言:javascript
复制
<?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语句。

EN

回答 1

Stack Overflow用户

发布于 2018-02-01 21:15:31

有一整块代码实际上并不是必需的:

$feat_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));

代码语言:javascript
复制
<img src="<?php
        echo $feat_image;
?>" alt="">

删除$feat_image行并将第2位替换为

<?php if ( has_post_thumbnail() ) the_post_thumbnail(); ?>

使用the_post_thumbnail()函数将输出必要的超文本标记语言,并自动填充alt文本,当然前提是文本已输入到媒体库中的图像帖子中。

希望这能有所帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48563345

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档