snipt

Ctrl+h for KB shortcuts

PHP

Drupal 7: Display image style on node template

1
2
3
4
5
6
<?php $image_uri = $node->field_illustration['und'][0]['uri'] ?>
<?php $image_url_with_style = image_style_url('thumbnail', $image_uri) ?>

<a href="<?php print $node_url ?>">
    <img src="<?php echo $image_url_with_style ?>" />
</a>
https://snipt.net/embed/e4cf4a2322be14ca21b40c624ffd401d/
/raw/e4cf4a2322be14ca21b40c624ffd401d/
e4cf4a2322be14ca21b40c624ffd401d
php
PHP
6
2016-12-26T07:45:07
True
False
True
Feb 19, 2013 at 04:38 AM
/api/public/snipt/56009/
drupal-7-display-image-style-on-node-template
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="nv">$image_uri</span> <span class="o">=</span> <span class="nv">$node</span><span class="o">-&gt;</span><span class="na">field_illustration</span><span class="p">[</span><span class="s1">&#39;und&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;uri&#39;</span><span class="p">]</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-2"><a name="L-2"></a><span class="cp">&lt;?php</span> <span class="nv">$image_url_with_style</span> <span class="o">=</span> <span class="nx">image_style_url</span><span class="p">(</span><span class="s1">&#39;thumbnail&#39;</span><span class="p">,</span> <span class="nv">$image_uri</span><span class="p">)</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="x">&lt;a href=&quot;</span><span class="cp">&lt;?php</span> <span class="k">print</span> <span class="nv">$node_url</span> <span class="cp">?&gt;</span><span class="x">&quot;&gt;</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> &lt;img src=&quot;</span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$image_url_with_style</span> <span class="cp">?&gt;</span><span class="x">&quot; /&gt;</span> </span><span id="L-6"><a name="L-6"></a><span class="x">&lt;/a&gt;</span> </span></pre></div> </td></tr></table>
"drupal 7", "image style", template