【问题标题】:Wordpress Thumbnail add action if no thumbnail如果没有缩略图,Wordpress 缩略图添加操作
【发布时间】:2013-10-16 01:08:10
【问题描述】:

我正在学习如何制作自己的 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? 谢谢

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    问题是由您使用的钩子引起的,它是在 post 循环开始时触发的。你必须检查wordpress hooks 看看你是否可以使用它们中的任何一个(可能最接近你需要的是the_content)但是如果在你需要的地方没有提供钩子,你必须创建自己的hook /action.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-17
      • 2014-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-23
      相关资源
      最近更新 更多