简体   繁体   中英

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. 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.

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. 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():

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.

So, check the values you get from your view, find how to get image URI and call it like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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