如果未设置发布自定义元数据,则显示正常状态

时间:2011-08-15 作者:juliusk

我在很大程度上是一个php noob,但我有一个网站循环的想法。我有它背后的想法,但也许你有一个想法如何将其转化为代码:

$customfield = get_specific_customfield

if $custom-field is = not empty
echo \'custom-field-input" class="\'

else

echo \'`<?php echo $thumbnail_src[0]; ?>" class="fancybox`\'
(我必须集成花哨的盒子来控制输入的显示方式)

1 个回复
最合适的回答,由SO网友:booota 整理而成

要获取单个自定义字段的值,请使用

<?php
    $post_id = $post->ID;
    $key = \'value\';  // change value to what custom field you are looking for
    // To retrieve only the first value of given key
    $customfield = get_post_meta($post_id, $key, \'true\');
    // To use as default
    $customfield = get_post_meta($post_id, $key);
    // Then check what you got
    if($customfield)
?>
    <img class="thumb" src="<?php echo get_post_meta($post_id, $key, true) ?>" alt="<?php the_title(); ?>" />
<?php
    else

    echo \'whatever you want to show by default\';
?>
进一步阅读转到codex

希望对你有帮助

结束

相关推荐