php - In template page_list get image attribute Concrete5 -
my following code based on 1.get current url 2.go through array , check if in url value = value in array this:
$on_this_link = "http://$_server[http_host]$_server[request_uri]"; foreach ($city_array $sandwich) { if (strpos($on_this_link, $sandwich) == true) { $sandwich = trim($sandwich, '/'); $city = $sandwich; if ($city == 'newyork') { foreach ($category_array $double_sandwich) { if (strpos($on_this_link, $double_sandwich) == true) { $double_sandwich = trim($double_sandwich, '/'); $category_is = $double_sandwich; loader::model('page_list'); $nh = loader::helper('navigation'); $pl = new pagelist(); $pl->filterbyattribute('city', '%' . $city . '%', 'like'); $pl->filterbyattribute('category','%'.$category_is.'%','like'); $pl->sortbydisplayorder(); $pagelist = $pl->get(); foreach ($pagelist $p) { echo '<li> <a href="' . $nh->getlinktocollection($p) . '">' .htmlspecialchars($p->getcollectionname()) . '</a> </li>'; ?> } } } }
so show me pages have same attribute url each of page has image attribute want show. how can pass image attribute??
check out comments in page list block's view template: https://github.com/concrete5/concrete5/blob/master/web/concrete/blocks/page_list/view.php#l33
you can image attributes putting code inside foreach ($pagelist $p)
loop:
$img = $p->getattribute('example_image_attribute_handle'); if ($img) { //you output original image @ full size so: echo '<img src="' . $img->getrelativepath() . '" width="' . $img->getattribute('width') . '" height="' . $img->getattribute('height') . '" alt="" />'; //or reduce size of original , output so: $thumb = loader::helper('image')->getthumbnail($img, 200, 100, false); //<--200 width, 100 height, , false cropping (change true if want crop image instead of resize proportionally) echo '<img src="' . $thumb->src . '" width="' . $thumb->width . '" height="' . $thumb->height . '" alt="" />'; }
Comments
Post a Comment