Jump to content

search page search fields


benbyf
 Share

Recommended Posts

Hi,

Having ploblems with this search page code.

I'm trying to get all images with tagged with the search query, which works currently. Then get a url and add <a> wrapping the image to a page that references that image in its image_select field - doesnt work.

if($input->get->q) {
    $q = $sanitizer->selectorValue($input->get->q);
    $input->whitelist('q', $q);
}

$matches = $pages->find("imageTags.title%=$q, limit=20");

if(count($matches)) {
    $out .= "<ul class='grid-list'>";
    foreach($matches as $m){
        // $name = $m->image->name;
        // $out = $name;
        // $mWork = $pages->find("image_select=$name, limit=1");
        // var_dump($mWork);
        $out .= "<li>";
        // $out .= "<a class='' href='{$mWork->url}'>";

        $image = $m->image;
        $image = $image->width(450);
        if($image) $out .= "<img src='$image->url'>";
        // echo "</a>";
        echo "</li>";
    }
    $out .= "</ul>";
}
Link to comment
Share on other sites

Hi,

Having ploblems with this search page code.

I'm trying to get all images with tagged with the search query, which works currently. Then get a url and add <a> wrapping the image to a page that references that image in its image_select field - doesnt work.

if($input->get->q) {
    $q = $sanitizer->selectorValue($input->get->q);
    $input->whitelist('q', $q);
}

$matches = $pages->find("imageTags.title%=$q, limit=20");

if(count($matches)) {
    $out .= "<ul class='grid-list'>";
    foreach($matches as $m){
        // $name = $m->image->name;
        // $out = $name;
        // $mWork = $pages->find("image_select=$name, limit=1");
        // var_dump($mWork);
        $out .= "<li>";
        // $out .= "<a class='' href='{$mWork->url}'>";

        $image = $m->image;
        $image = $image->width(450);
        if($image) $out .= "<img src='$image->url'>";
        // echo "</a>";
        echo "</li>";
    }
    $out .= "</ul>";
}

Is your image field an array? If so you may need to do 

foreach($m->image as $image) {
    $out .= "<img src='{$image->width(450)->url}' />";  
}

Correct me if I'm wrong, but I don't believe you need the if check as the page needs an image to have an image tag, so we know this will always return true. 

EDIT:

Re-read your code, it doesn't look like you are using the built in image tags? http://processwire.com/api/fieldtypes/images/ you will need to do an if check around the foreach. 

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

×
×
  • Create New...