top of page

Show Related Posts on your Wix blog by implementing below Corvid Code

Copy Code Snippet from below or download:

import wixLocation from 'wix-location';
import wixData from 'wix-data';

let currentPost

$w.onReady(function () {

    wixLocation.onChange(() => {
        return loadPostPage()
    })

    return loadPostPage()

    
});

function loadPostPage() {
    return $w("#post1").getPost().then(post => {
        currentPost = post
        return LoadRelatedPosts()
    })
}

function LoadRelatedPosts() {
    return wixData.query("Blog/Posts")
        .ne("_id", currentPost._id)
        .hasSome("hashtags", currentPost.hashtags)
        .limit(4)
        .find()
        .then(results => {
            $w("#relatedPostsRepeater").data = results.items;
        })
}

export function relatedPostsRepeater_itemReady($item, itemData, index) {
    $item("#imageRelated").src = itemData.coverImage;
    $item("#titleRelated").text = itemData.title;
    $item("#buttonRelated").link = itemData.postPageUrl;
}

bottom of page