在Wordpress中设置默认的帖子标题图像?

时间:2016-09-05 13:20:40

标签: php wordpress

如果没有手动设置,如何修改Wordpress主题以自动填充帖子的标题图像?对于PHP来说,我是一个完整的新手。

1 个答案:

答案 0 :(得分:1)

  

使用get_post_meta()函数可以实现此功能。您   可以在第一个参数中传递post 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..
          }
    }
?>