ankh2054 Posted May 22, 2014 Share Posted May 22, 2014 Hi all, I am having some problems pulling pages and showing their image field. The code below only shows one page and no other. image field = discuss_image (maximum file allowed = 1) // Pull all discussion pages $discussions = $pages->find("template=discussions"); foreach($discussions as $item) //Load and assign Image $discuss_image = $item->get("discuss_image"); $discuss_logo = $discuss_image->size(200,200, $image_options); $discuss_image_logo .= "<img class='img-rounded img-responsive' src='{$discuss_logo->url}'' alt='{$discuss_image->description}'' />"; //Theme each page echo " <a href='{$item->url}' class='list-group-item'> <div class='media col-md-3'> <figure class='pull-left'> <img class='media-object img-rounded img-responsive' src='{$item->discuss_image}' alt='placehold.it/350x250' > </figure> </div> <div class='col-md-6'> <h4 class='list-group-item-heading'>{$item->title}</h4> <p class='list-group-item-text'>{$item->body}</p> </div> <div class='col-md-3 text-center'> <h2> 14240 <small> votes </small></h2> <button type='button' class='btn btn-default btn-lg btn-block'> Vote Now! </button> <div class='stars'> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star-empty'></span> </div> <p> Average 4.5 <small> / </small> 5 </p> </div> </a> "; ?> If I have remove the image variables as per below code I get all pages. // Pull all discussion pages $discussions = $pages->find("template=discussions"); foreach($discussions as $item) //Theme each page echo " <a href='{$item->url}' class='list-group-item'> <div class='media col-md-3'> <figure class='pull-left'> <img class='media-object img-rounded img-responsive' src='placehold.it/350x250' alt='placehold.it/350x250' > </figure> </div> <div class='col-md-6'> <h4 class='list-group-item-heading'>{$item->title}</h4> <p class='list-group-item-text'>{$item->body}</p> </div> <div class='col-md-3 text-center'> <h2> 14240 <small> votes </small></h2> <button type='button' class='btn btn-default btn-lg btn-block'> Vote Now! </button> <div class='stars'> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star'></span> <span class='glyphicon glyphicon-star-empty'></span> </div> <p> Average 4.5 <small> / </small> 5 </p> </div> </a> "; ?> any ideas I think it has something to do with the maximum file = 1, but when I set it to 0 (array) then I get the following error. Error: Exception: Method Pageimages::size does not exist or is not callable in this context (in /var/www/www.bommachine.co.uk/wire/core/Wire.php line 320) Link to comment Share on other sites More sharing options...
horst Posted May 23, 2014 Share Posted May 23, 2014 just use some of this: { and } after the foreach! if you ommit them, only the next one following line is interpreted as code of the foreach loop. (in your second example the echo-statement) foreach($x as $y) { ... ... } 2 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted May 23, 2014 Share Posted May 23, 2014 That's right Horst, ASCII characters makes it so much more imaginable. ___, __)____)__ -)- ))) , \=_/ \__ __/). )_/=\ /6) \ __((_\_/\ / __/ \ /_/-\o____) / ,_/| \ \/ ))__|_ \_)o_' _.-' ,/:_/_ ___ '---`' \>__/ /o /---.,/_ \ ( / / /o / \) \ | (' \,/ ( / _____/ )___> / /\ ( / _______/,_____| |,( / ) ) / (_ \ | _/ o) \ /_ |/ \_ / ( '| (___,_/-` `.__ / ' \ | / ,---' / _/ \( \_/ / / )\ ( < b'ger ,./_(,, , \_/,,._ 1 Link to comment Share on other sites More sharing options...
ankh2054 Posted May 23, 2014 Author Share Posted May 23, 2014 thanks Horst. Sorry for more questions, but now I get the following error. Error: Call to a member function size() on a non-object $discuss_logo = $discuss_image->size(200,200, $image_options); Link to comment Share on other sites More sharing options...
horst Posted May 23, 2014 Share Posted May 23, 2014 .(`'`)----(`'`)----(`'`)----(`'`)----(`'`). | '.' '.' '.' '.' '.' | | | | | | | | This is a nice horse | | I like it, Martijn | | | | | | | '(`'`)----(`'`)----(`'`)----(`'`)----(`'`)' '.' '.' '.' '.' '.' 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted May 23, 2014 Share Posted May 23, 2014 Have you set your discuss_image image field to Maximum Files Allowed = 1 ? Link to comment Share on other sites More sharing options...
ankh2054 Posted May 23, 2014 Author Share Posted May 23, 2014 yes indeed. Link to comment Share on other sites More sharing options...
ankh2054 Posted May 23, 2014 Author Share Posted May 23, 2014 Wondered if it was due to not all discuss pages had images, so I did the below and it worked. / Pull all discussion pages $discussions = $pages->find("template=discussions"); foreach($discussions as $item) { //Load and assign Image if ($item->discuss_image->url){ $discuss_image = $item->get("discuss_image"); $discuss_logo = $discuss_image->size(200,200, $image_options); $discuss_image_logo .= "<img class='img-rounded img-responsive' src='{$discuss_logo->url}'' alt='{$discuss_image->description}'' />"; } else { $discuss_image_logo .= "<img class='img-rounded img-responsive' src='{$config->urls->templates}/styles/images/bom-mashien_logo.png' alt='BOMmachine' />"; } //Theme each page Link to comment Share on other sites More sharing options...
adrian Posted May 23, 2014 Share Posted May 23, 2014 thanks Horst. Sorry for more questions, but now I get the following error. Error: Call to a member function size() on a non-object $discuss_logo = $discuss_image->size(200,200, $image_options); Try this: $discuss_logo = $item->discuss_image->size(200,200, $image_options); Link to comment Share on other sites More sharing options...
ankh2054 Posted May 27, 2014 Author Share Posted May 27, 2014 thanks Adrian, I ended up using a if else clause, to show a default image if no image available. 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