How to show relevant Blog posts on a Dynamic page

Hello,
How would I display only relevant Blog posts on a Dynamic page?

For example, I have a Dynamic Page which shows songs by a particular artist. If I have written Blog posts about this artist before, how would I include a list of all Blog posts tagged (or categorized) with that artist’s name?

In my real-world example, I am showing a workout routine, and want to show my Blog pages about that particular workout routine.

Here’s a page on a routine called Sweat: https://www.seanarenas.com/WorkoutReviews/Sweat

You can drill down to that page from my Workout Series page here (just click Sweat)
https://www.seanarenas.com/WorkoutSeries/PiYo

So if I’ve written a Blog article (or more) on PiYo, or on Sweat, how would I get those articles to show on the PiYo and Sweat pages?

Hi Sean,

You can have a database that maps the type of workout to a blog post.
A but like that:
WORKOUT POST
sweat posturl1
sweat postUrl2
PiYo postUrl3

Then, on the dynamic page, use ’ wixLocation.path ’ to determine the right workout type, and use wixData.query() to fund relevant blog posts.
Then show on a table/repeater/any other way you like.

Good luck,
Liran.

So this would be a separate data collection that has the workout title Referencing the workout title in the workout data collection, and a second field for Post URL? Then I add one item for each blog post?

The I show a Repeater or a Table and Connect it to a dataset that I create to access the blog post link data collection, and it will be filtered by the Location.path and Data.query()?

Sorry if these seem like elementary questions, but I want to get this just right. What wouuld the Data.query() expression look like, exactly?

Thanks!

Hi sean,

Yes, create a new collection called ‘blogPosts’, make two fields (for example: workout and post).

Would look something like that:

const workoutName = wixLocation.path[0];

wixData.query("myCollection").eq("workout", workoutName).find().then( results => { 
let firstItem = results.items; 
//Items are now all posts that has type of workoutName
//Do something with them
}).catch( err => { let errorMsg = err; } );

Liran

I created this yesterday. I copied all data to live. Now I am looking for it and it is not showing up in my Database section. How do I find the missing data collection?

Strange, I went and created a new Database with the same name, and it “recovered” the missing database and put in the fields with brackets around them [workoutRoutine] and [postUrl]

Sorry for the newbie type question here, but now that I’ve put that code there and put my field name on it, what’s the next step?


Ideally, I’d like to have the name of the review (P90X3 Isometrix Review) be a link to the Blog post.

Hi,

A few things there:

  1. Using modules requires you to import them. for example:
import wixLoaction form 'wix-location';
//Now you can use wixLocation
import wixData form 'wix-data';
//Now you can use wixData
  1. Your code is in the global space.
    You need to put it at the place that it should work from. for example, if you want the coed to run when the page is loaded, put it indside of $w.onReady(). See:

$w.onReady(function() {
    //Do Your code here
})
  1. You’re using ‘workoutRoutine’ as a variable, but never assign a value to it.

Liran.