【问题标题】:Replace featured image with post meta用帖子元替换特色图片
【发布时间】:2019-07-15 14:04:43
【问题描述】:

我想要在 WordPress 中允许发布元条件的代码。例如,如果帖子具有元键“视频”,它将用元键替换特色图像;否则会显示特色图片。

特色图片代码:

<?php $image_ratio_case = my_image_ratio_case('1x'); do_action('my_thumbnail', 'my_thumb_16x9_0x', 'class-16x9', 1, NULL, $image_ratio_case);?>

元邮政编码:

<video autoplay loop muted width="100%" height="auto" src="<?php echo esc_html( get_post_meta( get_the_ID(), 'Video', true ) ); ?>"></video>

【问题讨论】:

  • 你试过什么?你被困在哪里了?
  • 我想要类似 if{ else { 的功能

标签: html wordpress video


【解决方案1】:

由于您没有提供任何提示,代码可以放在哪里以及您的实际问题是什么我只能给出这个答案,希望这会有所帮助:)

if (is_array(get_post_meta( get_the_ID(), 'Video', true )) || is_string(get_post_meta( get_the_ID(), 'Video', true ))) {
    //echo the video
} else {
    //echo the img
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-21
    • 2012-06-30
    相关资源
    最近更新 更多