Skip to content

Instantly share code, notes, and snippets.

@daveis
Created September 20, 2014 15:21
Show Gist options
  • Save daveis/e87da993ef99fea58d6d to your computer and use it in GitHub Desktop.
Save daveis/e87da993ef99fea58d6d to your computer and use it in GitHub Desktop.
Returns the prev/next article title while reading an article in Anchor CMS. Goes in your theme's functions.php file
// Return next and previous article titles
function dg_article_previous_title() {
$page = Registry::get('posts_page');
$query = Post::where('created', '<', Registry::prop('article', 'created'))
->where('status', '!=', 'draft');
if($query->count()) {
$article = $query->sort('created', 'desc')->fetch();
$page = Registry::get('posts_page');
return $article->title;
}
}
function dg_article_next_title() {
$page = Registry::get('posts_page');
$query = Post::where('created', '>', Registry::prop('article', 'created'))
->where('status', '!=', 'draft');
if($query->count()) {
$article = $query->sort('created', 'asc')->fetch();
$page = Registry::get('posts_page');
return $article->title;
}
}
@daveis
Copy link
Author

daveis commented Sep 20, 2014

This code goes in the functions.php file in my Manifesto theme.

This will allow you to use this code in your theme to show article titles for the prev/next pagination.

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