Skip to content

Instantly share code, notes, and snippets.

@katzueno
Last active August 29, 2015 14:17
Show Gist options
  • Save katzueno/d86ed4cdbc4e47a4081d to your computer and use it in GitHub Desktop.
Save katzueno/d86ed4cdbc4e47a4081d to your computer and use it in GitHub Desktop.
concrete5 公式活用ガイドブック ページリスト 5.7 対応版
<?php
defined('C5_EXECUTE') or die("Access Denied.");
$th = Loader::helper('text');
$c = Page::getCurrentPage();
$dh = Core::make('helper/date'); /* @var $dh \Concrete\Core\Localization\Service\Date */
$ih = Loader::helper('image');
?>
<?php if ( $c->isEditMode() && $controller->isBlockEmpty()) { ?>
<div class="ccm-edit-mode-disabled-item"><?php echo t('Empty Page List Block.')?></div>
<?php } else { ?>
<div class="menu-item-list">
<?php foreach ($pages as $page):
// Prepare data for each page being listed...
$buttonClasses = 'ccm-block-page-list-read-more';
$entryClasses = 'ccm-block-page-list-page-entry';
$title = $th->entities($page->getCollectionName());
$url = $nh->getLinkToCollection($page);
$target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target');
$target = empty($target) ? '_self' : $target;
$description = $page->getCollectionDescription();
$description = $controller->truncateSummaries ? $th->wordSafeShortText($description, $controller->truncateChars) : $description;
$description = $th->entities($description);
$thumbnail = false;
if ($displayThumbnail) {
$thumbnail = $page->getAttribute('thumbnail');
}
$includeEntryText = false;
if ($includeName || $includeDescription || $useButtonForLink) {
$includeEntryText = true;
}
if (is_object($thumbnail) && $includeEntryText) {
$entryClasses = 'ccm-block-page-list-page-entry-horizontal';
}
$date = $page->getCollectionDatePublic();
$date = $dh->date('Y年m月d日', strtotime($date));
$img = $page->getAttribute('thumbnail');
$thumb = $ih->getThumbnail($img, 208, 153, true);
//Other useful page data...
//$last_edited_by = $page->getVersionObject()->getVersionAuthorUserName();
//$original_author = Page::getByID($page->getCollectionID(), 1)->getVersionObject()->getVersionAuthorUserName();
/* CUSTOM ATTRIBUTE EXAMPLES:
* $example_value = $page->getAttribute('example_attribute_handle');
*
* HOW TO USE IMAGE ATTRIBUTES:
* 1) Uncomment the "$ih = Loader::helper('image');" line up top.
* 2) Put in some code here like the following 2 lines:
* $img = $page->getAttribute('example_image_attribute_handle');
* $thumb = $ih->getThumbnail($img, 64, 9999, false);
* (Replace "64" with max width, "9999" with max height. The "9999" effectively means "no maximum size" for that particular dimension.)
* (Change the last argument from false to true if you want thumbnails cropped.)
* 3) Output the image tag below like this:
* <img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />
*
* ~OR~ IF YOU DO NOT WANT IMAGES TO BE RESIZED:
* 1) Put in some code here like the following 2 lines:
* $img_src = $img->getRelativePath();
* $img_width = $img->getAttribute('width');
* $img_height = $img->getAttribute('height');
* 2) Output the image tag below like this:
* <img src="<?php echo $img_src ?>" width="<?php echo $img_width ?>" height="<?php echo $img_height ?>" alt="" />
*/
/* End data preparation. */
/* The HTML from here through "endforeach" is repeated for every item in the list... */ ?>
<div class="menu-item clearfix">
<div class="photo">
<a href="<?php echo $url ?>" target="<?php echo $target ?>">
<img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />
</a>
</div>
<div class="summary">
<h2><a href="<?php echo $url ?>" target="<?php echo $target ?>" rel="bookmark"><?php echo $title ?></a></h2>
<p><?php echo $description;?></p>
</div>
</div>
<?php endforeach; ?>
<?php if (count($pages) == 0): ?>
<div class="ccm-block-page-list-no-pages"><?php echo $noResultsMessage?></div>
<?php endif;?>
</div><!-- end .ccm-block-page-list -->
<?php if ($showPagination): ?>
<?php echo $pagination;?>
<?php endif; ?>
<?php } ?>
<?php
defined('C5_EXECUTE') or die("Access Denied.");
$th = Loader::helper('text');
$c = Page::getCurrentPage();
$dh = Core::make('helper/date'); /* @var $dh \Concrete\Core\Localization\Service\Date */
?>
<?php if ( $c->isEditMode() && $controller->isBlockEmpty()) { ?>
<div class="ccm-edit-mode-disabled-item"><?php echo t('Empty Page List Block.')?></div>
<?php } else { ?>
<div class="news-list hfeed">
<?php foreach ($pages as $page):
// Prepare data for each page being listed...
$buttonClasses = 'ccm-block-page-list-read-more';
$entryClasses = 'ccm-block-page-list-page-entry';
$title = $th->entities($page->getCollectionName());
$url = $nh->getLinkToCollection($page);
$target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target');
$target = empty($target) ? '_self' : $target;
$description = $page->getCollectionDescription();
$description = $controller->truncateSummaries ? $th->wordSafeShortText($description, $controller->truncateChars) : $description;
$description = $th->entities($description);
$thumbnail = false;
if ($displayThumbnail) {
$thumbnail = $page->getAttribute('thumbnail');
}
$includeEntryText = false;
if ($includeName || $includeDescription || $useButtonForLink) {
$includeEntryText = true;
}
if (is_object($thumbnail) && $includeEntryText) {
$entryClasses = 'ccm-block-page-list-page-entry-horizontal';
}
$date = $page->getCollectionDatePublic();
$date = $dh->date('Y年m月d日', strtotime($date));
//Other useful page data...
//$last_edited_by = $page->getVersionObject()->getVersionAuthorUserName();
//$original_author = Page::getByID($page->getCollectionID(), 1)->getVersionObject()->getVersionAuthorUserName();
/* CUSTOM ATTRIBUTE EXAMPLES:
* $example_value = $page->getAttribute('example_attribute_handle');
*
* HOW TO USE IMAGE ATTRIBUTES:
* 1) Uncomment the "$ih = Loader::helper('image');" line up top.
* 2) Put in some code here like the following 2 lines:
* $img = $page->getAttribute('example_image_attribute_handle');
* $thumb = $ih->getThumbnail($img, 64, 9999, false);
* (Replace "64" with max width, "9999" with max height. The "9999" effectively means "no maximum size" for that particular dimension.)
* (Change the last argument from false to true if you want thumbnails cropped.)
* 3) Output the image tag below like this:
* <img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" />
*
* ~OR~ IF YOU DO NOT WANT IMAGES TO BE RESIZED:
* 1) Put in some code here like the following 2 lines:
* $img_src = $img->getRelativePath();
* $img_width = $img->getAttribute('width');
* $img_height = $img->getAttribute('height');
* 2) Output the image tag below like this:
* <img src="<?php echo $img_src ?>" width="<?php echo $img_width ?>" height="<?php echo $img_height ?>" alt="" />
*/
/* End data preparation. */
/* The HTML from here through "endforeach" is repeated for every item in the list... */ ?>
<div class="hentry entry">
<div class="published"><?php echo $date?></div>
<div class="entry-title">
<a href="<?php echo $url ?>" target="<?php echo $target ?>" rel="bookmark"><?php echo $title ?></a>
</div>
</div>
<?php endforeach; ?>
<?php if (count($pages) == 0): ?>
<div class="ccm-block-page-list-no-pages"><?php echo $noResultsMessage?></div>
<?php endif;?>
</div><!-- end .ccm-block-page-list -->
<?php if ($showPagination): ?>
<?php echo $pagination;?>
<?php endif; ?>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment