0

我的以下代码基于 1.获取当前 URL 2.遍历数组并检查 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 具有相同属性的页面每个页面都有我想要显示的图像属性。我怎样才能传递这个图像属性?

4

2 回答 2

1

查看页面列表块的视图模板中的注释: 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="" />';
    }
于 2013-05-10T15:45:21.010 回答
0

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

Loader::model('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'); $thumb = $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
                    }
                }   
    }

所以一切正常但仍然感谢回复!欣赏

于 2013-05-10T18:43:38.483 回答