Wordpress自訂欄位的使用

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

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

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

<?php
/*
Plugin Name: Post-Custom
Plugin URI:
Description:
Version: 0.0
Author:
Author URI:
*/

function the_whether($text_whether='the_whether', $display=true) {
$the_whether = post_custom('the_whether');
if( $display ) {
echo $text_whether . $the_whether;
} else {
return $the_whether;
}
}

?>

2.在模板中想要出現這個欄位內容的地方貼上
<? if(post_custom('the_whether')) { ?>

<?php the_whether('天氣 ', true); ?>

<?php } ?>

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

回應

JY2CH9 xpikgiqnntei, [url=http://jvulmxhwxwsl.com/]jvulmxhwxwsl[/url], [link=http://cvsntdyuqlqd.com/]cvsntdyuqlqd[/link], http://kygavvsbrhez.com/

發表新回應

這個欄位的內容會保密,不會公開顯示。
  • 自動將網址與電子郵件位址轉變為連結。
  • 可使用的 HTML 標籤:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • 自動斷行和分段。

更多關於格式選項的資訊