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.
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.
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?
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; } );
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]
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
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
})
You’re using ‘workoutRoutine’ as a variable, but never assign a value to it.