Giter Club home page Giter Club logo

Comments (9)

daftspunk avatar daftspunk commented on July 19, 2024 4

This is now available via both the blog post component and the blog post model

{% set nextPost = blogPost.nextPost %}
{% set lastPost = blogPost.previousPost %}

from blog-plugin.

abass avatar abass commented on July 19, 2024

I was wondering this aswell. Tried for a solution for a bit until I finally just let it slide & let Disqus recommend posts. Would like to know this too.

from blog-plugin.

michballard avatar michballard commented on July 19, 2024

I'm really interested in this solution too. Would be great if it was built into the plugin.

from blog-plugin.

jhenahan avatar jhenahan commented on July 19, 2024

Add

$this->next = $this->page['next'] = $this->getNextPost();
$this->prev = $this->page['prev'] = $this->getPrevPost();

to your onRun() and then define the following:

protected function getNextPost() {
    $id = $this->post->id;
    $post = BlogPost::isPublished()->where('id', '>' , $id)->first();

    return $post;
}

protected function getPrevPost() {
    $id = $this->post->id;
    $post = BlogPost::isPublished()->where('id', '<', $id)->first();

    return $post;
}

I used a technique like this in a similar module I worked on.

from blog-plugin.

daveharrisonnet avatar daveharrisonnet commented on July 19, 2024

Looks promising. Where exactly do i add all this code? (all in the onRun() of the page)
. I assume I have to manually include next and previous links in my partial?

All Ok , got it sorted with a few tweaks wasn't sure how to call it onto page but got there in the end. Thanks for the pointers ;)

from blog-plugin.

daveharrisonnet avatar daveharrisonnet commented on July 19, 2024

UPDATE, sort of worked but some strange foo going on where won;t continue through the full list of articles. If I get it sorted i 'll let you know what I did

from blog-plugin.

jhenahan avatar jhenahan commented on July 19, 2024

I added all of those in my component class in my plugin. I'll work on a PR later to add them to this plugin.

from blog-plugin.

Hessel91 avatar Hessel91 commented on July 19, 2024

Do you have a screenshot where to place the code?

from blog-plugin.

fenriz07 avatar fenriz07 commented on July 19, 2024

My solution:
`use rainlab\blog\models\Post;

function onStart(){
$slug = $this->param('slug');
$this['post_active'] = Post::isPublished()->where('slug', '=' , $slug)->get();
$post_active = Post::isPublished()->where('slug', '=' , $slug)->get();
$this['NextPost'] = Post::isPublished()->where('id', '>' , $post_active[0]['id'])->get();
$this['LastPost'] = Post::isPublished()->where('id', '<',$post_active[0]['id'])->get();
}`

Thanks jhenahan

from blog-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.