Wordpress自訂欄位的使用


在Wordpress發表文章的地方有個叫自訂欄位的東東,
一直讓我很好奇那是啥…
這次因為想要把花水木的流水帳弄成像日記一樣,
想要有個[天氣]的欄位,
所以就去稍微研究了一下。知道有個使用自訂欄位的方式。

不過這方式還滿爛的,所以希望有會寫程式的朋友多多指教啊!

1.首先,寫外掛檔, 然後上傳-啟用外掛

/*<br />
Plugin Name: Post-Custom<br />
Plugin URI: <br />
Description: <br />
Version: 0.0<br />
Author: <br />
Author URI:<br />
*/<br />
<br />
<br />
<br />
function the_whether($text_whether='the_whether', $display=true) {<br />
$the_whether = post_custom('the_whether');<br />
if( $display ) {<br />
echo $text_whether . $the_whether;<br />
} else {<br />
return $the_whether;<br />
}<br />
}<br />
<br />
<br />
?&gt;

2.在模板中想要出現這個欄位內容的地方貼上

&lt;? if(post_custom('the_whether')) {  ?&gt;<br />
<br />
&lt;div class=&quot;post-whether&quot;&gt;<br />
<br />
&lt;?php the_whether('天氣 ', true); ?&gt;<br />
<br />
&lt;/div&gt;<br />
<br />
&lt;?php } ?&gt;

3.發表文章時在自訂欄位加一個the_whether, 欄位內容打天氣,像這樣

4.然後就好啦!


發表迴響

你的電子信箱絕對不會被公開。 必填的項目標記為 *

*
*