(1) プレゼンで紹介したショートコードサンプル ----- function integral_output_func( $atts ) { extract( shortcode_atts( array( 'from' => '0', 'to' => '1', ), $atts )); return '∫' . $from . '' . $to . ''; } add_shortcode( 'integral', 'integral_output_func' ); ----- shortcode_attsは、受け入れる属性名とそのデフォルト値を設定。 「属性名」「デフォルト値」の連想配列 add_shortcodeは、関数をショートコードとして登録。 「投稿画面で記入するショートコード名」「呼び出す関数」 ショートコード名は自由に付けられるので、被らないようにする。 既存のショートコードの一覧は配列$shortcode_tagsに格納されている。 詳しい解説は http://wp.kyoto-math.jp/shortcode.html http://wp.kyoto-math.jp/how_to_shortcode.html http://wpdocs.sourceforge.jp/ショートコード_API ショートコードを利用しているサイトの例は http://www.kyoto-math.jp/ /****************************************************/ (2) カスタムフィールドのデータをTABLEで出力 ----- function customfield_output_func( $atts ) { extract( shortcode_atts( array( ), $atts )); $custom_keys = get_post_custom_keys(); if ($custom_keys) { $outdata = ""; foreach ($custom_keys as $key) { if ( "_" != substr($key,0,1) ) { $outdata .= ""; } } $outdata .= "
"; $outdata .= $key; $outdata .= ""; $valuearray = get_post_custom_values($key); $outdata .= implode(",",$valuearray); $outdata .= "
"; } return $outdata; } add_shortcode( 'customtable', 'customfield_output_func' ); ----- カスタムフィールドには、WPが使う内部データが、 アンダーバーで始まる変数として格納されているので、 if ( "_" != substr($key,0,1) ) { で取り除く カスタムフィールドは1つのキーに複数の値を割り当て可能なので、 (値が1つの場合も)返り値は配列になっているので、 implode(",",$valuearray); で文字列に展開 カスタムフィールドの解説は http://wp.kyoto-math.jp/customfield.html http://wp.kyoto-math.jp/how_to_customfield.html /****************************************************/ (3) ログインしているユーザーのみに表示するテキスト ----- function loggedin_func( $atts, $content = null ) { extract( shortcode_atts( array( ), $atts )); if(is_user_logged_in()) { return $content ; } else { return "You are not logged in."; } } add_shortcode( 'loggedin', 'loggedin_func' ); ----- /****************************************************/ (4) グーグルマップを挿入するショートコード 緯度と経度のデータはカスタムフィールドから取得 ----- function googlemap_output_func( $atts, $content = null ) { extract( shortcode_atts( array( 'mapid' => 'map', 'zoom' => '3', ), $atts )); $lng = implode("",get_post_custom_values("lng")); $lat = implode("",get_post_custom_values("lat")); $data = "\n"; return $data; } add_shortcode( 'googlemap', 'googlemap_output_func' ); ----- get_post_custom_values("lng")と get_post_custom_values("lat")で カスタムフィールドの緯度経度データを取得 投稿画面では、[googlemap]だけでOK 利用にはGoogle Map API キー取得が必要 http://code.google.com/intl/ja/apis/maps/ ----- より高度なグーグルマッププラグイン Google Maps for WordPress 日本語版 http://wppluginsj.sourceforge.jp/i18n-ja_jp/google-maps-for-wp/ Google Maps Anywhere http://wppluginsj.sourceforge.jp/googlemaps-anywhere/ /****************************************************/ (5) PollDaddy プラグイン 記事中にアンケートを表示するプラグイン。 記事挿入にショートコードを利用。 http://www.polldaddy.com/ http://wordpress.org/extend/plugins/polldaddy/ /****************************************************/ (6) AddQuicktag プラグイン 投稿画面でワンクリックでタグが挿入できるプラグイン。 HTMLモードでのみ有効。 良く使うショートコードを登録しておくと便利。 ボタンは日本語でもOK http://wordpress.org/extend/plugins/ /****************************************************/ (7) WordPressの日本語版開発、ドキュメント作成協力者募集中 http://wpdocs.sourceforge.jp/ 神戸ワードプレスユーザー会発足 http://kobe.wordbench.org/