Created
August 16, 2015 15:51
-
-
Save cazuki/cafa03f635ba7f6e30c3 to your computer and use it in GitHub Desktop.
WordPressでチャット風会話形式コンテンツを表示する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function balloon_shortcode($atts, $content = null) { | |
extract(shortcode_atts(array( | |
'face' => '1', | |
'name' => '自分の名前', | |
'align' => 'right' | |
),$atts)); | |
switch ($face) { | |
case 1: | |
$imageUrl = get_stylesheet_directory_uri().'/テーマフォルダ内の画像までのパス'; | |
break; | |
case 2: | |
$imageUrl = get_avatar_url(get_avatar($comment, 90)); //コメント用アバターを表示 | |
break; | |
default: | |
$imageUrl = $face; //任意のアバター画像を挿入する | |
break; | |
} | |
return '<div class="balloon-box balloon-'.$align.' clrfix"> | |
<div class="balloon-icon"><img src="'.$imageUrl.'" width="90" height="90" alt="'.$name.'"><br><span>'.$name.'</span></div> | |
<div class="balloon-serif"><div class="balloon-content">'.$content.'</div></div> | |
</div>'; | |
} | |
add_shortcode('chat','balloon_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment