Skip to content

Instantly share code, notes, and snippets.

@katzueno
Last active August 29, 2015 14:14
Show Gist options
  • Save katzueno/6b1fb907bf4272020683 to your computer and use it in GitHub Desktop.
Save katzueno/6b1fb907bf4272020683 to your computer and use it in GitHub Desktop.
News Category Image Label Sample Script
<?php
defined('C5_EXECUTE') or die("Access Denied.");
/*
* Page List * Page List Plus concrete5 custom templates sample
* ページリスト & ページリストプラスのカスタムテンプレートサンプル
* How to display category lebel by using Localizer add-on
* Localizer アドオンを使って、カテゴリラベルの色分け表示の色分け表示をする
*
* 1. You need to prepare CSS class that define the category label color
* 2. Create Select type Page attribute, name it with "news_type" handle
* 3. Register your class name
* 4. Set Localizer and translate the value if you use non-English languages
* 5. Create the page with news_type attribute selected
* 6. Place the Page List block
* ATTENTION: On line 30, we modifided the date format to Japanese, change the format
*/
$th = Loader::helper('text');
$dh = Loader::helper('date');
$v = View::getInstance();
?>
<ul class="news__list">
<?php foreach ($pages as $page):
$title = $th->entities($page->getCollectionName());
$url = $nh->getLinkToCollection($page);
$target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target');
$target = empty($target) ? '_self' : $target;
$date = $page->getCollectionDatePublic();
$date = $dh->date('Y年m月d日', strtotime($date));
$news_type = $page->getAttribute('news_type');
$news_type_handle = '';
$news_type_name = '';
if ($news_type instanceof SelectAttributeTypeOptionList) {
$news_type_options = $news_type->getOptions();
foreach ($news_type_options as $o) {
$news_type_handle = $o->getSelectAttributeOptionValue();
$news_type_handle = $th->handle($news_type_handle);
$news_type_name = $o->getSelectAttributeOptionDisplayValue();
}
}
?>
<li class="<?php echo $news_type_handle;?>"><span class="date"><?php echo $date;?><img src="<?php echo $v->getThemePath();?>/images/newsbtn_<?php echo $news_type_handle;?>.png" alt="<?php echo $news_type_name;?>" class="filtercategory"/></span>
<a href="<?php echo $url ?>" target="<?php echo $target ?>" class="listcontent"><?php echo $title ?></a>
</li>
<?php endforeach; ?>
</ul><!-- end .event__list -->
<?php if ($showPagination): ?>
<div class="pagination__box">
<ul class="pagination__list">
<li><?php echo $paginator->getPrevious('<') ?></li>
<?php echo $paginator->getPages('li') ?>
<li><?php echo $paginator->getNext('>') ?></li>
</div>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment