wardrobecms / core-archived

Wardrobe Core Files
http://wardrobecms.com/
MIT License
142 stars 31 forks source link

Feature Request: Add Prev/Next Post #94

Closed tomsonar closed 10 years ago

tomsonar commented 10 years ago

Is this something we can add somewhere to alter Wardrobe without having to make edits to the package code? Or does it need to be implemented in the core?

Basically, here's what is desired: http://blog.marcomonteiro.net/post/how-to-add-previous-and-next-links-on-wardrobe

Thanks

ericlbarnes commented 10 years ago

You can set this up as a view composer:

View::composer('default.post', function($view) {

    $prev = DB::table('posts')->orderBy('id', 'asc')->where('id', '>', $view->post->id)->where('active', '1')->first();
    $next = DB::table('posts')->orderBy('id', 'desc')->where('id', '<', $view->post->id)->where('active', '1')->first();

    $view->with(compact('prev', 'next'));
});

Change the 'default.post' to whatever theme you are using.

tomsonar commented 10 years ago

Thanks. I added a view composer class, service provider, and added it to the bootstrap process and composer.json. Phew that was a workout =) Hopefully this is still a good thing to add to the core package one day. Seems popular.