IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    WordPress如何在文章最前面输出特色图像

    小旭旭发表于 2015-10-14 01:24:04
    love 0

    WordPress的特色图像可以不插入编辑器,可以单独设置。很多时候我们为了美观,想在文章页的内容开头,就插入这篇文章的特色图像,向下面一样的效果,特色图像是在文章最前面。

    文章开头是特色图像
    文章开头是特色图像

    实现方法,在你的主题文件functions.php插入

    add_filter( 'the_content', 'featured_image_before_content' ); 
     
     function featured_image_before_content( $content ) { 
        if ( is_singular('post') && has_post_thumbnail()) {
            $thumbnail = get_the_post_thumbnail();
    
            $content = $thumbnail . $content;
    		
    		}
    
        return $content;
    }
    

    在文章页loop的插入即可。

    其他方法还可以通过先获取WordPress特色图像地址,在做输出,这个就比较简单,不多说。



沪ICP备19023445号-2号
友情链接