Jon E Posted August 6, 2015 Share 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 Link to comment Share on other sites More sharing options...
titanium Posted August 6, 2015 Share Posted August 6, 2015 Does $page->images even exist? The if-condition asks for $page->slideshow_images... Link to comment Share on other sites More sharing options...
Jon E Posted August 6, 2015 Author Share Posted August 6, 2015 Hi, It does, and I'm getting just the filename.jpg output... not the whole directory. Thanks Jon Link to comment Share on other sites More sharing options...
diogo Posted August 6, 2015 Share 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... Link to comment Share on other sites More sharing options...
Jon E Posted August 6, 2015 Author Share Posted August 6, 2015 Thanks so much Link to comment Share on other sites More sharing options...
Soma Posted August 6, 2015 Share 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"; Link to comment Share on other sites More sharing options...
diogo Posted August 6, 2015 Share 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 Link to comment Share on other sites More sharing options...
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