使用子主题函数.php中的Wordpress函数时出错
所以我的Wordpress中有一个儿童主题,非常好用。我的子主题中有一个functions.php,用于一些简单的短代码。但是,我正在制作一个新的快捷码,我需要根据帖子id抓取帖子的特色图片。因此我有:使用子主题函数.php中的Wordpress函数时出错,wordpress,parent-child,Wordpress,Parent Child,所以我的Wordpress中有一个儿童主题,非常好用。我的子主题中有一个functions.php,用于一些简单的短代码。但是,我正在制作一个新的快捷码,我需要根据帖子id抓取帖子的特色图片。因此我有: function kwn_in_th_news_teaser($atts){ if($atts['count']){ $count = $atts['count']; }else{ $count = 4;
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');
那么我如何从我的孩子体内使用基本的wordpress函数呢?我在谷歌上搜索了一个多小时都没有用。非常感谢您的帮助
~James您的问题可能有误,但WordPress中的函数是
get\u post\u thumbnail\u id()
而不是get\u post\u thumbnail\u id
woooooow/facepalm x 100感谢您指出这一点。我真不敢相信我被绊倒了大约一个小时。。。我想我现在需要休息一下。。。感谢我们所有人。我相信你们对这个很熟悉,但万一你们不熟悉,就这样吧。当我使用WordPress时,我每天都使用它。每当我在函数中遇到错误时,我都会查找它。这就是我发现你的问题的原因,我查了一下函数,看看它使用了什么参数,然后意识到输入的参数是错误的。
Fatal error: Call to undefined function get_the_post_thumbnail_id() in /blah/blah/blah/theme-child/functions.php on line 115