エプソンダイレクト株式会社
Home > 2013年2月16日(土曜日)

2013年2月16日(土曜日)

Custom Field Template を使う ~ 実際に表示してみる

Category: WordPress | Posted By at 23:59:11

WordPress › Custom Field Template « WordPress Plugins

ほったらかしにしていたわけではありません。
他に書かないといけないネタが多かったからです。
じゃあ、ネタが切れたから書いてる?
お客さん、鋭いですねぇ~(ぉぃっ)。
(ここまでコピペ)

Custom Field Template で入力したデータは
カスタムフィールドのデータなので、
表示については普通のものと同じです。

カスタムフィールドの表示は

1
post_custom( 'key_name' );

で表示できるのでこれを使ってもいいのですが、

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function the_cf( $key, $title = "" ) {
    if( $ret = get_cf( $key ) ){
        if( $title ){
            $title .= ":";
        }
        print $title . $ret;
    }
}
 
function get_cf( $key, $array = false ){
    $cf = post_custom( $key );
    if( $cf ){
        if( !is_array( $cf ) ){
            if( $array ){
                return array( nl2br( $cf ) );
            }else{
                return nl2br( $cf );
            }
        }else{
            sort( $cf );
            if( $array ){
                return $cf;
            }else{
                return implode( ",", $cf );
            }
        }
    }else{
        return false;
    }
}

私はこんな感じで関数化してWordPress の標準関数っぽくして使っています。
ただ将来バッティングしなければいいのですが… (^o^;;;

HP Directplus -HP公式オンラインストア- デル株式会社 東芝ダイレクト 富士通パソコンFMVの直販サイト富士通 WEB MART ソフマップ・ドットコム