snipt

Ctrl+h for KB shortcuts

PHP

Use PHP in Panels to single out a Node

$nid = ctools_context_keyword_substitute('%node:nid', array(), $contexts);
return $nid == 1062615656 || $nid == 1062637051 || $nid == 1062665081 || $nid == 1062664956;
https://snipt.net/embed/60ac2923ad7136d1f85f013dc0dee67c/
https://snipt.net/raw/60ac2923ad7136d1f85f013dc0dee67c/
60ac2923ad7136d1f85f013dc0dee67c
php
PHP
2
2016-09-28T08:11:44
True
False
False
/api/public/snipt/63854/
use-php-in-panels-to-single-out-a-node
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="x">$nid = ctools_context_keyword_substitute(&#39;%node:nid&#39;, array(), $contexts);</span> </span><span id="L-2"><a name="L-2"></a><span class="x">return $nid == 1062615656 || $nid == 1062637051 || $nid == 1062665081 || $nid == 1062664956;</span> </span></pre></div> </td></tr></table>
7, Drupal

Text only

Drupal 7 - Override page title with site slogan

1
2
3
4
5
function diagoro_preprocess_html(&$vars) {
  if(drupal_is_front_page()) {
    $vars['head_title'] = implode(' | ', array(drupal_get_title(), variable_get('site_name'), variable_get('site_slogan')));
  }
}
https://snipt.net/embed/664831fac18c42b3d69db2813cf29d48/
https://snipt.net/raw/664831fac18c42b3d69db2813cf29d48/
664831fac18c42b3d69db2813cf29d48
text
Text only
5
2016-09-27T22:41:41
True
False
False
/api/public/snipt/55974/
override-page-title-with-site-slogan
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>function diagoro_preprocess_html(&amp;$vars) { </span><span id="L-2"><a name="L-2"></a> if(drupal_is_front_page()) { </span><span id="L-3"><a name="L-3"></a> $vars[&#39;head_title&#39;] = implode(&#39; | &#39;, array(drupal_get_title(), variable_get(&#39;site_name&#39;), variable_get(&#39;site_slogan&#39;))); </span><span id="L-4"><a name="L-4"></a> } </span><span id="L-5"><a name="L-5"></a>} </span></pre></div> </td></tr></table>
"page title", Drupal

PHP

Drupal - get author user name from $uid

1
2
3
4
<?php 
$username = $node->name;
print $username;
?>
https://snipt.net/embed/fb5183fb2791bb7a020c5b9aee6694b9/
https://snipt.net/raw/fb5183fb2791bb7a020c5b9aee6694b9/
fb5183fb2791bb7a020c5b9aee6694b9
php
PHP
4
2016-09-28T05:45:51
True
False
False
/api/public/snipt/49355/
drupal-get-author-user-name-from-uid
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$username</span> <span class="o">=</span> <span class="nv">$node</span><span class="o">-&gt;</span><span class="na">name</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="k">print</span> <span class="nv">$username</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
$uid, Drupal

PHP

Drupal - If content type ... do something

<?php if($node->type=='node-type-name'){ ?>
https://snipt.net/embed/89ac9897d3a1461373c9959d92fb2749/
https://snipt.net/raw/89ac9897d3a1461373c9959d92fb2749/
89ac9897d3a1461373c9959d92fb2749
php
PHP
1
2016-09-19T09:10:54
True
False
False
Oct 31, 2012 at 05:06 AM
/api/public/snipt/49354/
drupal-if-content-type-do-something
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="k">if</span><span class="p">(</span><span class="nv">$node</span><span class="o">-&gt;</span><span class="na">type</span><span class="o">==</span><span class="s1">&#39;node-type-name&#39;</span><span class="p">){</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
Drupal
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.