简体   繁体   English

将图像样式应用于从Drupal站点上的单独节点渲染的图像?

[英]Apply image styling to images rendered from separate nodes on Drupal site?

I have a page on my website that filters content from a separate page using the entityFieldQuery method. 我的网站上有一个页面,该页面使用EntityFieldQuery方法从单独的页面过滤内容。 The problem is that the images I am filtering on to the new page need a different image style applied to them so that they load into smaller images. 问题是我过滤到新页面上的图像需要应用不同的图像样式,以便它们加载到较小的图像中。 I have picture mapping set up on the site but I have only applied it via the Drupal workbench in the image fields where you can choose an image style from a dropdown. 我在站点上设置了图片映射,但是我仅通过Drupal工作台在图像字段中应用了它,您可以从下拉菜单中选择图像样式。

The code below is my entityfieldquery and the conditional statement that creates the content that is being filtered from another page on to the current page. 下面的代码是我的entityfieldquery和条件语句,该条件语句创建从另一个页面过滤到当前页面的内容。 Is there any way I can revise this code to apply a different image style to the images that are being generated? 有什么办法可以修改此代码,以对正在生成的图像应用不同的图像样式?

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
    ->propertyCondition('status', NODE_PUBLISHED)
    ->propertyCondition('type', 'Blog')
    ->propertyCondition('created', array($old_date, $current_date),'BETWEEN')
    ->propertyOrderBy('created', 'DESC')
    ->fieldCondition('field_blog_categories', 'tid', $term_id)
    ->fieldCondition('field_blog_categories', 'tid', array('55', '26'))
    ->range(0, 9);
    $result = $query->execute();
    }
    if(isset($result['node'])) {
        $blog_items_nids = array_keys($result['node']);
        $blog_items = entity_load('node', $blog_items_nids);    
        if (count($blog_items)>2){
        $data = array();
        foreach ($blog_items as $blg) {
            $field_blog_header_image = field_view_field('node', $blg, 'field_blog_header_image', 'picture');
            $temp_blog_cat = field_view_field('node', $blg, 'field_blog_categories');                       
            $data[$temp_blog_cat['#items'][0]['tid']][] = array(
                'blog' => $temp_blog_cat["#object"]->title,
                'img'  => isset($field_blog_header_image) ? render($field_blog_header_image) : '',
                'link' => $temp_blog_cat['#object']->path['alias'],
            );
        }
    ?>

Yes, you can use function image_style_url(): 是的,您可以使用函数image_style_url():

https://api.drupal.org/api/drupal/modules!image!image.module/function/image_style_url/7 https://api.drupal.org/api/drupal/modules!image!image.module/function/image_style_url/7

That function will give you path to image in any style you pass to it as long as you can acquire and pass image URI to it as parameter. 该函数将为您提供传递给图像的任何样式的图像路径,只要您可以获取图像URI并将其作为参数传递给它即可。

So, check the values you get from your view, find how to get image URI and call it like: 因此,检查从视图中获取的值,找到如何获取图像URI并按如下方式调用它:

$image_path = image_style_url('style_name', $uri);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM