カスタムPHPウィジェットマネージャープラグインのユースケースを紹介します。
Facebook PHP SDKを適当なところに保存。以下ではテーマ内に。
Developer登録して、Facebookアプリを作成する。
例えば、Facebookページで、公開されているイベントをAPIで取得するには、content部に以下のように記述する。
<?php
// require facebook
require_once( get_template_directory() .'/library/facebook/facebook.php' );
// facebookでdeveloperとして作ったアプリ
$config = array();
$config['appId'] = 'your-appId';
$config['secret'] = 'your-secret';
$config['fileUpload'] = false; // optional
$facebook = new Facebook($config);
try{
$events = $facebook->api('/{some facebook page id}/events');
if( !empty( $events ) ){
foreach( $events['data'] as $event ){
$event_id = $event['id'];
// get event
$the_event = $facebook->api('/' . $event_id . '?fields=id,name,description,cover,end_time' );
if( !empty( $the_event ) ){
if( strtotime( $the_event['end_time'] ) < time() )
continue;
$fb_url = 'https://www.facebook.com/events/' . $event_id;
echo '<div style="width:100%;border:4px solid brown;margin: 10px 0 10px 0;padding:10px;"><h2><a href="' . $fb_url . '" target="_blank">' . $the_event['name'] . '</a></h2>';
if( $the_event['cover']['source'] != ''){
echo '<div style="float:right;"><a href="' . $fb_url . '" target="_blank"><img src="' . $the_event['cover']['source'] . '" style="width:200px;height:auto;" /></a></div>';
}
echo nl2br( $the_event['description'] );
echo '</div><div style="clear:both:"></div>';
}
}
}
}
catch (Exception $e){
echo '';
}
?>
このshortcodeを、挿入したい箇所に記述すればOK。
利用例:さつまや本店様
- プロの寿司職人が教える寿司教室 (http://www.satsumayahonten.com/kyoshitsu )
- 寿司教室のお問い合わせ (http://www.satsumayahonten.com/contact_sushiclass )
