ページリスト・カスタムテンプレート:縮小画像や Twitter、Facebook ボタンを表示

2011年6月11日 at 16:39

2011年6月、名古屋 concrete5 勉強会で話した、ページリストに、縮小画像を表示するためのサンプルです。

取り急ぎ、サンプルだけ置いておきます。

だれか、解説して〜( ̄ー ̄)ニヤリ

縮小画像「page_thumbnail」属性の画像を300x250に強制的にリサイズして表示。
ページリストのリンク先の Twitter のツイート、Facebook の「いいね」の数を表示。

<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
$textHelper = Loader::helper("text");
// now that we're in the specialized content file for this block type,
// we'll include this block type's class, and pass the block to it, and get
// the content

if (count($cArray) > 0) { ?>
<div class="ccm-page-list">
<div class="divider"></div>
<?php
for ($i = 0; $i < count($cArray); $i++ ) {
$cobj = $cArray[$i];
$title = $cobj->getCollectionName();
$lfb = LibraryFileBlockController::getFile($cobj->getAttribute('page_thumbnail')->fID);
$YokosoPageListThumbnail300 = $lfb->getThumbnail(300,250)->src;
if ($YokosoPageListThumbnail300) { ?>
<div class="ccm-page-list-thumbnail">
<a href="<?php echo $nh->getLinkToCollection($cobj)?>">
<img src="<?php echo $YokosoPageListThumbnail300 ?>" alt="<?php echo $title ?>" />
</a></div>
<?php
} else {
?>
<div class="ccm-page-list-thumbnail">
<a href="<?php echo $nh->getLinkToCollection($cobj)?>">
<img src="<?php echo BASE_URL . DIR_REL;?>/themes/japanexp_simple/images/pagelistnoimage300.gif" alt="" width="300" height="250" />
</a>
</div>
<?php }
?>
<div class="ccm-page-list-social">
<a href="http://twitter.com/share" class="twitter-share-button" data-url="<?php echo BASE_URL . DIR_REL . $nh->getLinkToCollection($cobj)?>" data-text="<?php echo $title?>" data-count="horizontal" data-via="YokosoNews">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script><fb:like layout="button_count" font="arial" href="<?php echo BASE_URL . DIR_REL . $nh->getLinkToCollection($cobj)?>"></fb:like>
</div>
<h3 class="ccm-page-list-title"><a href="<?php echo $nh->getLinkToCollection($cobj)?>"><?php echo $title?></a></h3>
<div class="ccm-page-list-date"><?php echo $cobj->getCollectionDatePublic ('M jS, Y'); ?></div>
<div class="ccm-page-list-date">Posted by <?php
$YokosoPageAuthor = User::getByUserID($cobj->getCollectionUserID());
print $YokosoPageAuthor->getUserName();
?></div>
<div class="ccm-page-list-description">
<?php
if(!$controller->truncateSummaries){
echo $cobj->getCollectionDescription();
}else{
echo $textHelper->shorten($cobj->getCollectionDescription(),$controller->truncateChars);
}
?> <a href="<?php echo $nh->getLinkToCollection($cobj)?>">Read More</a>
</div>
<div class="divider" style="clear:both"></div>
<?php }
if(!$previewMode && $controller->rss) {
$btID = $b->getBlockTypeID();
$bt = BlockType::getByID($btID);
$uh = Loader::helper('concrete/urls');
$rssUrl = $controller->getRssUrl($b);
}
?>
</div>
<?php }

if ($paginate && $num > 0 && is_object($pl)) {
$pl->displayPaging();
}

?>