Skip to content

Instantly share code, notes, and snippets.

@jessedobbelaere
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessedobbelaere/10019209 to your computer and use it in GitHub Desktop.
Save jessedobbelaere/10019209 to your computer and use it in GitHub Desktop.
Fork CMS projects module - Show more than 1 spotlight item
<?php
/**
* Get related items based on tags
*
* @param int $id
* @param int[optional] $limit
* @return array
*/
public static function getSpotlightProject()
{
// Change "getRecord" to "getRecords" so that it will retrieve more than 1 item from the database
// I removed ORDER BY RAND() because it shouldn't be in random order anymore I think?'
$items = (array) FrontendModel::getContainer()->get('database')->getRecords(
'SELECT i.*, m.url, c.title AS category_title, m2.url AS category_url
FROM projects AS i
INNER JOIN meta AS m ON i.meta_id = m.id
INNER JOIN projects_categories AS c ON i.category_id = c.id
INNER JOIN meta AS m2 ON c.meta_id = m2.id
WHERE i.language = ? AND i.hidden = ? AND i.spotlight = ?
',
array(FRONTEND_LANGUAGE, 'N', 'Y')
);
// It should get the image for every item in the array, so I added a foreach loop here. I used the $key to add the extra fields (full_url, image) to the original items array.
foreach($items as $key => $item) {
if($item) {
$img = FrontendModel::getContainer()->get('database')->getRecord('SELECT * FROM projects_images WHERE project_id = ?', array((int)$item['id']));
if($img) $items[$key]['image'] = FRONTEND_FILES_URL . '/projects/' . $item['id'] . '/128x128/' . $img['filename'];
else $items[$key]['image'] = '/' . APPLICATION . '/modules/projects/layout/images/dummy.png';;
$items[$key]['full_url'] = FrontendNavigation::getURLForBlock('projects', 'detail') . '/' . $item['url'];
}
}
return $items;
}
{*
variables that are available:
- {$widgetProjectsSpotlight}: contains an array with a spotlight project
To show more than 1 item in the spotlight, I added an iteration and an extra div with class "spotlight-item"
so you can style it with CSS.
*}
{option:widgetProjectsSpotlight}
<section id="projectSpotlight" class="mod">
<div class="inner">
<header class="hd">
<h3>{$lblSpotlight|ucfirst}</h3>
</header>
<div class="bd content">
{iteration:widgetProjectsSpotlight}
<div class="spotlight-item">
<a title="{$widgetProjectsSpotlight.title}" href="{$widgetProjectsSpotlight.full_url}">
<h4>{$widgetProjectsSpotlight.title}</h4>
<img alt="{$widgetProjectsSpotlight.title}" src="{$widgetProjectsSpotlight.image}">
</a>
<p>{$widgetProjectsSpotlight.introduction}</p></div>
</div>
{/iteration:widgetProjectsSpotlight}
</div>
</section>
{/option:widgetProjectsSpotlight}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment