PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
So it's the old file before the recent changes were made. OK. Look at the inputs that getSrcSet accepts and look at what you're passing it. Do you see why it's not working?
Hang on yeah I have messed that up.
Just looked at your code, where is "resize.php" coming from??
That's not a file I know of.
IS this all going into ONE .php file? to then include on pages like this.
Sorry have i gotten lost a bit??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
I called it resize.php, you called it functionConsumerResize.php. They're meant to be the same file. I pasted the entire contents of my resize.php earlier. It contains five functions, including the modified getSrcSet that accepts the resize type string rather than an array of sizes.
What I suspect would ultimately be best is to wrap the whole thing in a class and have it autoloaded, but let's focus on getting things working before we progress to that stage.
OMG! So I just saw the (__DIR__) areas I don't need, so I removed the braces.
I then loaded the page.
Saw another one. Fixed that.
Reloaded. And the page came up. Nothing unusual.
Checked the code, all srcsets are in there.
Checked the images/pages folder, and low and behold, a load of images have been generated!
My next job then is to add this brief code into the Products section, and the 'wide' section, and see what happens.
I need a closer inspection of those functions as well, to really get my head around it.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Awesome! Glad it's working out so well. Essentially, getting it working in other areas should entail including the file, calling the same function, and changing the second parameter as needed. That's it.
You've included the file with the functions? It's not complaining about functions not existing or anything? Have you tried var_dump and exit inside the getSrcSet function to make sure it's being called?
Gaaaarrrr... I was being an idiot. I forget I had two sections of products One that isn't being used!!!
That's why.
Here's a step into this challenge then.
We also use a thing called Stock Banners. So the admin chap when he creates products and uploads their photos, he also create a 'stock banner'.
When he wants to promote a product but doesnt' have time to create a banner at the time, he might have one "in stock". A library if you like.
So he types in the stock code, up comes the product banner (if one was set), checks the box and that gets used.
This resize on the fly tool would be good to do those too. Same format as 'products'.
But - it needs to be stored in a different folder.
products goes in /images/page.
stock banners go in /images/stockbanners.
So how could I go above saying:
$srcset = getSrcSet($image, 'stockbanners');
Using the same size as products, but storing in different place??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
A couple of things. First, you'd need to define some sizes for 'stockbanners' in your getWidths function, otherwise it won't know what to resize to. Next is we've got images/pages hard-coded into these functions. They'd need to be modified to accept the path as a parameter so the functions can know where to look for images and where to save the ones they create. Think that's enough info for you to get started making these modifications?
I can see how to add it to the list for sizing, but not how to tell it which folders to use for stockbanners.
In theory, it's /images/pages, else, /images/stockbanners.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.