(抱歉我的英文),我希望解釋!ElseIf自定義字段不同的值(Wordpress)
我正在尋找解決方案來顯示名爲「cw」的自定義字段的不同輸出。我的申請定製多大用處的主題,所以我創建了一個功能,以簡化您的來電:
/**
* Get custom field of the current page
* $type = string|int
*/
function my_getcustomfield($filedname, $page_current_id = NULL)
{
if($page_current_id==NULL)
$page_current_id = get_page_id();
$value = get_post_meta($page_current_id, $filedname, true);
return $value;
}
說這個,我創建了我的主題提出的習俗:
<?php $video_code = my_getcustomfield('cw',get_the_ID()); if(!empty($video_code)) : ?>
<div class="video_code"><?php echo $video_code; ?></div>
由於自定義值是一個URL,請鍵入:http://127.0.0.1:4001/?f=cadbe2676d5108523f931a68eedb3582,我需要提取該ID。使用這種技術PHP Regex to get youtube video ID?,我修改了我的自定義以這種方式提交:
<?php $video_code = my_getcustomfield('cw',get_the_ID()); $url = $video_code; parse_str(parse_url($url, PHP_URL_QUERY)); if(isset($video_code[0])){ ?>
<div cacaolink="http://127.0.0.1:4001/?f=<?php echo $f; ?>"></div>
<?php } else { ?>
<?php echo 'Video n.d.'; ?></div>
<?php endif; } ?>
這樣一切完美。
現在,自定義值可與下面列出:
<div cacaolink="http://127.0.0.1:4001/megavideo/megavideo.caml?videoid="></div>
<div cacaolink="http://127.0.0.1:4001/videobb/videobb.caml?videoid="></div>
<div cacaolink="http://127.0.0.1:4001/?f="></div>
**最後這裏的問題是:我如何可以根據自定義值使用ELSEIF?
任何幫助表示讚賞:)**
因此,你需要簡短的是從上面定義的3個結構之一的網址中提取「視頻ID」部分,對嗎?如果是,您需要的只是下一個: – karevn