2016-09-05 3 views

答えて

1

get_post_meta()関数を使用すると、この機能を実現できます。 は、最初のパラメータに投稿IDを渡すことができます。 にcustom_field_nameを使用できます。そして、それはデータベースまたは で利用可能である以下のコードのようにチェックしてください。

このコードを試してください。

<?php 

    if(is_single() & !is_home()) 
    { 
     $myfield = 'custom_field_name'; // Change this to the name of the custom field you use.. 
     $postimage = get_post_meta($post->ID, $myfield, true); 
      if($postimage) 
      { 
       // If the field has a value.. set image path using value... 
      } 
      elseif(!$postimage) 
      { 
       // If no value than set Default image path.. 
      } 
    } 
?> 
関連する問題