Skip to content

Instantly share code, notes, and snippets.

@tim-bec
Created December 20, 2013 12:43
Show Gist options
  • Save tim-bec/8054315 to your computer and use it in GitHub Desktop.
Save tim-bec/8054315 to your computer and use it in GitHub Desktop.
MetaModels preview / next link in details
<?php
$projectId = null;
$nextProject = null;
$prevProject = null;
$currProject = null;
$nextLink = null;
$prevLink = null;
if (count($this->items) > 0) {
$projectId = $this->items[0]->get('id');
$projects = MetaModelFactory::byTableName('mm_projects');
$filter = $projects->prepareFilter(!ID!,array()); //List filter Your filter ID = !ID!
$res = $projects->findByFilter($filter, 'sorting');
$nextIsNext = false;
while (($item = $res->getItem()) && $item !== false) {
if ($nextIsNext) {
$nextProject=$item;
break;
}
elseif ($item->get('id') === $projectId) {
$currProject = $item;
$nextIsNext = true;
}
elseif ($nextProject === null) {
$prevProject = $item;
}
$res->next();
}
$params = '';
if ($nextProject !== null) {
$nextLink = $this->generateFrontendUrl($GLOBALS['objPage']->row(), '/'.$nextProject->get('alias').$params);
}
if ($prevProject !== null) {
$prevLink = $this->generateFrontendUrl($GLOBALS['objPage']->row(), '/'.$prevProject->get('alias').$params);
}
}
?>
<div class="project-nav">
<?php if($prevLink !== null): ?>
<a href="<?php echo $prevLink;?>" class="prev">{{iflng::en}}previous{{iflng}}{{iflng::de}}zurück{{iflng}}</a>
<?php endif; ?>
<?php if($nextLink !== null): ?>
<a href="<?php echo $nextLink;?>" class="next">{{iflng::en}}next{{iflng}}{{iflng::de}}vor{{iflng}}</a>
<?php endif; ?>
</div>
@Schnubl
Copy link

Schnubl commented Jun 6, 2016

Hallo tim,
ich bekomm bei dem Code eine Fehlermeldung:

Deprecated notice: MetaModels\Factory::byTableName is deprecated and will get removed. Use method MetaModels\Factory::getMetaModel() instead. in composer/vendor/metamodels/core/src/MetaModels/Factory.php on line 188

Gibts davon eine aktuelle Variante?
Danke für die Info!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment