2017-01-13 38 views
1

私はWordpressで子テーマを使用しています。私はいくつかの簡単なショートコードのために私の子供のテーマにfunctions.phpを持っています。しかし、私は新しいショートコードを作成しています。私はpost_idに基づいて投稿の特集画像をつかむ必要があります。だから私はしている:子テーマのfunctions.phpからWordpress関数を使用しているエラー

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 

は、どのように私は私の子供の中から、基本的なワードプレスの機能を使用できますか?私は1時間以上これをグーグルで使っていない。どんな助けでも大歓迎です。

〜ジェームズ

答えて

2

これは、あなたの質問にタイプミスかもしれませんが、WordPressの関数はget_post_thumbnail_id()ないget_the_post_thumbnail_id

+0

Wooooooowです。/facepalm x 100それを指摘してくれてありがとう。私はそれが約1時間私を上げたと信じられない...私は今休憩を取る必要があると思う...ありがとう@caldwellysr – semaj0

+1

私たちすべてに起こる。私はあなたが[WordPress Codex](https://codex.wordpress.org)に精通していると確信していますが、そうでない場合に備えてです。私がWordPressをやったとき、毎日それを使っていました。いつも私は関数を使ってエラーを見つけたので、私はそれを探します。それがどのように私はあなたの問題を発見した、私はそれが間違って入力されたパラメータを確認し、それを実現するために関数を調べた。 – CaldwellYSR

関連する問題