如果没有缩略图,Wordpress缩略图添加操作

时间:2013-10-16 01:08:10

标签: php wordpress wordpress-plugin

我正在学习如何创建自己的Wordpress插件,目前我很困惑如果帖子中没有缩略图然后我使用默认图像作为缩略图。 我使用的代码:

add_action( 'the_post', 'mythumb' );
function mythum(){
   if (!has_post_thumbnail()) {
    $defaultthum = "http://example.com/default.jpg"
    echo ('<div class="featured-thumbnail"><img width="150" height="150" src="'.$defaultthum.'" class="attachment-featured wp-post-image" alt="7" title="" /></div>')
   }
}

我的问题:默认图片缩略图不在正确的位置。 看到这张图片:http://s22.postimg.org/ezt05f59d/Lm_XUp.png 任何的想法?或钩子不是the_post? 感谢

1 个答案:

答案 0 :(得分:0)

问题是由您使用的钩子引起的,它是在后置循环的开始时触发的。您必须检查wordpress hooks以查看是否可以使用其中任何一个(可能最接近您需要的是the_content),但如果您不需要它,则必须创建自己的{ {3}} / hook

相关问题