2015-06-27 145 views
0

我想使用自定義字段創建鏈接+標題。WordPress |使用自定義字段創建鏈接+標題

我的意思是?

,比如我有自定義字段命名爲:mylink1,mylink2,mylink3(等)

mylink1值是 「谷歌| http://www.google.com

mylink2值是」 臉譜| http://www.facebook.com

mylink3 value is」Twitter | http://www.twitter.com

我想的WordPress上顯示單個帖子主題此代碼:

<a href="http://google.com">Google</a> 

<a href="http://www.facebook.com">Facebook</a> 

<a href="http://www.twitter.com">Twitter</a> 

我想WordPress的每mylinkX自定義字段值 我怎樣才能做到這一點顯示在單個帖子主題驗證碼?

+0

您測試了我的答案嗎? –

回答

1

當然,沒問題:)

使用此代碼..

<?php 

$val = get_post_meta(get_the_ID(), 'mylink1', true); 

// brake the link on half :) 
$desc = substr($val , 0, strpos($val, '|')) ; 
$href = substr($val , strpos($val, '|') + 1) ; 

// in your template show the link with structure! 

echo "<a href='" . $$href . "'>" . $desc . "</a>"; 

如果開始或結束不正確,則索引關閉,請告知我是否有效。

+0

desc很好。 href是空的。 –

+0

哦.. $$ href哈哈一個$太多:)謝謝! –

+0

很高興工作:) –

相關問題