使用来自子主题functions.php的Wordpress函数的错误

时间:2017-01-13 19:00:26

标签: wordpress parent-child

所以我的Wordpress中有一个儿童主题,效果很好。我的子主题中有一些functions.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功能呢?我已经谷歌搜索了一个多小时无济于事。非常感谢任何帮助。

〜詹姆斯

1 个答案:

答案 0 :(得分:2)

这可能是您问题中的拼写错误,但WordPress中的功能是get_post_thumbnail_id()而非get_the_post_thumbnail_id