Skip to content

Instantly share code, notes, and snippets.

@tbaddade
Last active July 30, 2020 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbaddade/8694849 to your computer and use it in GitHub Desktop.
Save tbaddade/8694849 to your computer and use it in GitHub Desktop.
<?php
if (!function_exists('pr')) {
function pr()
{
array_map(function ($x) {
echo '<pre>'; print_r($x); echo '</pre>';
}, func_get_args()); die;
}
}
if (! function_exists('getNextArticle')) {
function getNextArticle($category_id, $ignore_offline = false) {
$articles = OOArticle::getArticlesOfCategory($category_id, $ignore_offline);
$next_article = null;
$save_next_article = false;
foreach ($articles as $article) {
if ($article->getId() != REX_ARTICLE_ID && $next_article == null) {
$next_article = $article;
}
if ($save_next_article) {
$next_article = $article;
break;
}
if ($article->getId() == REX_ARTICLE_ID) {
$save_next_article = true;
}
}
if ($next_article == null) {
$children = OOCategory::getChildrenById($category_id, $ignore_offline);
if (count($children) > 0) {
foreach ($children as $child) {
$next_article = getNextArticle($child->getId(), $ignore_offline);
if ($next_article instanceof OOArticle) {
break;
}
}
}
}
return $next_article;
}
}
$a = getNextArticle(REX_CATEGORY_ID, true);
pr($a);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment