Jon E Posted August 6, 2015 Posted August 6, 2015 Hi, Could someone give me a helping hand please? I have the below code: <?php // Show the gallery widget if there are slideshow images attached to this press article if(count($page->slideshow_images)) { echo '<div id="article_slideshow_widget">'; $n = 0; echo "$page->images->first()->url;<img src='http://i.imgur.com/0heduk5.png' class='article_slideshow_widget_zoom'></div>"; $n++; } echo ""; ?> I want to output the first image from the images field in the article_slideshow_widget div, but it is only giving me the filename currently (I removed the img tags to see what was being output as I was being given a broken image as the complete URL isn't there!) Sure I'm close but would really be grateful for a pointer. Thanks so much Jon
titanium Posted August 6, 2015 Posted August 6, 2015 Does $page->images even exist? The if-condition asks for $page->slideshow_images...
Jon E Posted August 6, 2015 Author Posted August 6, 2015 Hi, It does, and I'm getting just the filename.jpg output... not the whole directory. Thanks Jon
diogo Posted August 6, 2015 Posted August 6, 2015 Try to set the image url to a variable first: $n = 0; $image_url = $page->images->first()->url; echo "{$image_url}<img src...
Soma Posted August 6, 2015 Posted August 6, 2015 Or if inside a string and multiple chains use {} echo "{$page->images->first()->url}..."; If only one chain it doesn't need it like echo "$page->url";
diogo Posted August 6, 2015 Posted August 6, 2015 Like Soma said. For more details see here http://php.net/manual/en/language.types.string.php#language.types.string.parsing
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now