カテゴリの編集
list_category.tmpl内にjavascriptも記述!
古い忍者でJSON形式データから画像を一つだけ取り出す
//画像を一つだけ取り出す。 //JSONから配列作る。 // $ary = array($entry["json"]["option"]); //画像を一つだけ取り出す自作関数。ブログパスを添えて。 // $entry['blogurl'].jsonImageOne($ary); <mt:XXXAssets> アイテムが登録されている時の処理 <mt:Else> アイテムが登録されていない時の処理 </mt:XXXAssets> // empty($_SERVER["HTTPS"]) ? "http://" : "https://") . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; // esc_url // $thisurl = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ? // if ( strstr($thisurl, $entry[permalink]) ) {?//現在のURL echo (empty($_SERVER["HTTPS"]) ? "http://" : "https://") . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
htmlコンテンツの最初のIMGを返す関数
php_lib_publishの最後に追加済:古いシステムを使う場合は注意!
function get_content_firsrimage($content) {
$pattern = '/<img.*?src\s*=\s*[\"|\'](.*?)[\"|\'].*?>/i';
if(preg_match($pattern, $content, $imgs)){
if(is_array($imgs)&& isset($imgs[1])) return $imgs[1];
}
return false;
};
古い忍者との混在で画像をリンクにする
//-- echoで出力される内容を変数に入れて分岐させる
<?php
$ary = array($entry["json"]["links"]);
ob_start();
jsonImageOne($ary);
$imgonejson = ob_get_contents();
ob_end_clean();
?>
<?php if ($imgonejson == '') { ?>
<img src="<?=get_content_firsrimage($entry['body']);?>" class="img-h img-center">
<?php } else { ?>
<img src="<?=$entry['blogurl'];?><?=$imgonejson;?>" class="img-h img-center">
<?php }; ?>