Is it possible to apply custom code to individual elements within the Post List widget?

I would like to change the hyperlink and background color of the Category Label depending on what category is listed.

I’ll build a repeater from scratch if I have to, but would prefer to use the Wix feature for Post List since it’s readily available.

Hello,
Yes, it is possible to apply custom code to individual elements within the Post List widget in Wix. You can use the “onItemReady” event handler to access and manipulate the properties of individual elements within the Post List widget.

Here’s an example code snippet that demonstrates how to change the hyperlink and background color of the Category Label depending on the category listed:
$w(“#postList”).onItemReady(($item, itemData, index) => {
let categoryLabel = $item(“#categoryLabel”);
switch(itemData.category) {
case “Category 1”:
categoryLabel.link = “new-category-1-link”;
categoryLabel.style.backgroundColor = “#FF0000”;
break;
case “Category 2”:
categoryLabel.link = “new-category-2-link”;
categoryLabel.style.backgroundColor = “#00FF00”;
break;
// Add more cases for other categories as needed
default:
// Use default link and background color
break;
}
});
In this example, we’re using the “onItemReady” event handler to iterate through each item in the Post List and access the properties of its corresponding elements. We’re using a switch statement to check the category of each item and set the hyperlink and background color of the Category Label accordingly. You can customize the code to fit your specific needs and add more cases for other categories as needed .

Thank you for the response. Whe I apply the onItemReady event handler to my post list in code it does not recognize the function.

error: “property ‘onItemReady’ does not exist in IFrame”

I have even used ‘onItemReady’ successfully with another custom repeater I created on the same page, so not sure why they are treated differently.