我正在学习如何制作自己的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?谢谢
发布于 2013-10-16 14:36:17
这个问题是由您使用的钩子引起的,它是在post循环的请求时触发的。您必须检查wordpress hooks,看看是否可以使用它们中的任何一个(可能最接近您需要的是the_content),但是如果在您需要的地方没有提供钩子,那么您将不得不创建自己的hook / action。
https://stackoverflow.com/questions/19393663
复制相似问题