Jump to content

Loading pages and showing image field of each


ankh2054
 Share

Recommended Posts

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

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) {

    ...

    ...

}

  • Like 2
Link to comment
Share on other sites

That's right Horst, ASCII characters makes it so much more imaginable.  :lol:

                               ___,
                            __)____)__
                              -)- )))
                      ,       \=_/ \__
                   __/).          )_/=\
                  /6)   \      __((_\_/\
                 /   __/ \    /_/-\o____)
                / ,_/|    \   \/  ))__|_
                \_)o_'     _.-'  ,/:_/_    ___
                     '---`' \>__/  /o /---.,/_  \
                     (      /  /  /o /       \)  \
                     |        ('  \,/        (   /
                _____/         )___> /       /\ (
               / _______/,_____|  |,(       /  ) )
              / (_     \  |   _/ o)  \     /_  |/
              \_ /     ( '| (___,_/-` `.__  /  '
                        \ |     / ,---' / _/
                         \(     \_/    / /
                          )\          ( <
                 b'ger ,./_(,, ,       \_/,,._
  • Like 1
Link to comment
Share on other sites

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


.(`'`)----(`'`)----(`'`)----(`'`)----(`'`).

| '.' '.' '.' '.' '.' |

| |

| |

| |

| This is a nice horse |

| I like it, Martijn |

| |

| |

| |

'(`'`)----(`'`)----(`'`)----(`'`)----(`'`)'

'.' '.' '.' '.' '.'

  • Like 1
Link to comment
Share on other sites

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...