在模板page_list获取图像属性Concrete5


In template page_list get image attribute Concrete5

我下面的代码是基于1.获取当前URL2.遍历数组并检查是否在url value = to value in array这样做:

$on_this_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 
foreach ($city_array as $sandwich) {
    if (strpos($on_this_link, $sandwich) == true) {
        $sandwich = trim($sandwich, '/');
        $city     = $sandwich;
        if ($city == 'newyork') {
            foreach ($category_array as $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 as $p) {
                    echo '<li> <a href="' . $nh->getLinkToCollection($p) . '">' .htmlspecialchars($p->getCollectionName()) . '</a> </li>';
                         ?>
                 }
           }
     }
}

所以它将只显示与URL具有相同属性的页面每个页面都有我想展示的图像属性。我怎么能传递这个图像属性??

查看页面列表块视图模板中的注释:https://github.com/concrete5/concrete5/blob/master/web/concrete/blocks/page_list/view.php L33

您可以通过在foreach ($pagelist as $p)循环中放入以下代码来获取图像属性:

    $img = $p->getAttribute('example_image_attribute_handle');
    if ($img) {
        //you could output the original image at its full size like so:
        echo '<img src="' . $img->getRelativePath() . '" width="' . $img->getAttribute('width') . '" height="' . $img->getAttribute('height') . '" alt="" />';
        //or you could reduce the size of the original and output that like so:
        $thumb = Loader::helper('image')->getThumbnail($img, 200, 100, false); //<--200 is width, 100 is height, and false is for cropping (change to true if you want to crop the image instead of resize proportionally)
        echo '<img src="' . $thumb->src . '" width="' . $thumb->width . '" height="' . $thumb->height . '" alt="" />';
    }

谢谢,但我已经用另一种方式做到了!我没有使用

装载机:模型("page_list");

我用:

$blockType = BlockType::getByHandle('page_list');

硬编码的块!

$th = Loader::helper('text');
$ih = Loader::helper('image');
$page_current = Page::getCurrentPage();
$page_2 = $page_current->getCollectionHandle();

$img = $page->getAttribute('product');$拇指=$ih->getThumbnail($img, 240,150, false);

之后我稍微修改了一下上面的代码:

 $on_this_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 
    foreach ($city_array as $sandwich) {
        if (strpos($on_this_link, $sandwich) == true) {
            $sandwich = trim($sandwich, '/');
            $city     = $sandwich;
            if ($city == 'newyork') {
            foreach ($category_array as $double_sandwich) {
           if (strpos($on_this_link, $double_sandwich) == true) {
            $double_sandwich = trim($double_sandwich, '/');
            $category_is = $double_sandwich;
            $city_att = $page->getAttribute('city', '%' . $city . '%', 'like');
           $sub_cat_att = $page->getAttribute('category','%'.$category_is.'%','like');  ?>               
           <?php if($city == $city_att && $category_is == $sub_cat_att){  ?><li><img src="<?php  echo $thumb->src ?>" width="<?php  echo $thumb->width ?>" height="<?php  echo $thumb->height ?>" alt="" />
    <h3> <?php  echo $title ?></h3>
    <div class="product_description">
    <?php  echo $description ?>
    </div>
    <a href="<?php  echo $url ?>" target="<?php  echo $target ?>">Read More... </a>
    </li>  <?php } ?> <?php
                    }
                }   
    }

所以一切都在工作,但仍然感谢响应!Apreciate