使用子主题函数中的 Wordpress 函数时出错.php



所以我在我的Wordpress中有一个子主题,效果很好。我有一个函数.php在我的孩子主题中用于一些简单的短代码。但是,我正在制作一个新的短代码,我需要抓取基于post_id的帖子的特色图片。所以我有:

function kwn_in_th_news_teaser($atts){
         if($atts['count']){
             $count = $atts['count'];
         }else{
             $count = 4;
         }
        global $wpdb;
        $query = $wpdb->get_results('SELECT * FROM table ORDER BY timestamp DESC',ARRAY_A);
        foreach($query as $news) {
            if($i == $count) break;
            $thumbnail_id = get_the_post_thumbnail_id($news['postID']);
            $thumbnail = wp_get_attachment_image_src($thumbnail_id, 'liberty-blog-full');
            $return = '';
            $return .= '
                    <div class="col-md-3">
                        <div class="profile-sidebar">
                            <div class="profile-userpic">
                                <img src="'.$thumbnail.'" class="img-responsive" alt="">
                            </div>
                            <div class="profile-usertitle">
                                <div class="profile-usertitle-name">
                                    '.$news['news_headline'].'
                                </div>
                                <div class="profile-usertitle-job">
                                    '.$news['kid_name'].'
                                </div>
                            </div>
                            <p></p>
                            <div class="profile-userbuttons">
                                <button type="button" class="btn btn-success btn-sm">View News</button>
                                <button type="button" class="btn btn-info btn-sm">View Story</button>
                            </div>
                        </div>
                    </div>
            ';
        }
        return $return; 
 }
 add_shortcode('news_teaser','kwn_in_th_news_teaser');

但是,我收到有关未定义函数的错误:

Fatal error: Call to undefined function get_the_post_thumbnail_id() in /blah/blah/blah/theme-child/functions.php on line 115

那么,我怎样才能从孩子体内使用基本的wordpress功能呢?我已经在谷歌上搜索了一个多小时,但无济于事。任何帮助都非常感谢。

~詹姆斯

这可能是

您问题中的错字,但WordPress中的功能get_post_thumbnail_id()不是get_the_post_thumbnail_id

最新更新