snipt

Ctrl+h for KB shortcuts

CSS

AddThis float fix

1
2
3
4
5
/* 
 * fix for addthis when used in a float
 * addthis plugin is wrapped in a div with clear:both, this can interfere with floating
*/
div.atclear { display:none !important; }
https://snipt.net/embed/3f4bc148d8f1dae790e1a62ff8292a65/
/raw/3f4bc148d8f1dae790e1a62ff8292a65/
3f4bc148d8f1dae790e1a62ff8292a65
css
CSS
5
2019-08-19T18:03:21
True
False
False
/api/public/snipt/37244/
addthis-float-fix
<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></span><span id="L-1"><a name="L-1"></a><span class="c">/* </span> </span><span id="L-2"><a name="L-2"></a><span class="c"> * fix for addthis when used in a float</span> </span><span id="L-3"><a name="L-3"></a><span class="c"> * addthis plugin is wrapped in a div with clear:both, this can interfere with floating</span> </span><span id="L-4"><a name="L-4"></a><span class="c">*/</span> </span><span id="L-5"><a name="L-5"></a><span class="nt">div</span><span class="nc">.atclear</span> <span class="p">{</span> <span class="nb">display</span><span class="o">:</span><span class="nb">none</span> <span class="cp">!important</span><span class="p">;</span> <span class="p">}</span> </span></pre></div> </td></tr></table>
"float fix", addthis, css

Bash

Add new Git repo on local machine

1
2
3
4
5
6
7
// borrowed from http://qugstart.com/blog/ruby-and-rails/create-a-new-git-remote-repository-from-some-local-files-or-local-git-repository/

#On local machine
cd foo_project
git init
git add *
git commit -m "My initial commit message"
https://snipt.net/embed/bef4e291498b234b9e9da35f3170bdf1/
/raw/bef4e291498b234b9e9da35f3170bdf1/
bef4e291498b234b9e9da35f3170bdf1
bash
Bash
7
2019-08-15T14:41:30
True
False
False
/api/public/snipt/36716/
add-new-git-repo-on-local-machine
<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> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>// borrowed from http://qugstart.com/blog/ruby-and-rails/create-a-new-git-remote-repository-from-some-local-files-or-local-git-repository/ </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c1">#On local machine</span> </span><span id="L-4"><a name="L-4"></a><span class="nb">cd</span> foo_project </span><span id="L-5"><a name="L-5"></a>git init </span><span id="L-6"><a name="L-6"></a>git add * </span><span id="L-7"><a name="L-7"></a>git commit -m <span class="s2">&quot;My initial commit message&quot;</span> </span></pre></div> </td></tr></table>
git, repo

PHP

D7 .info template

1
2
3
4
5
name = MODULE_NAME
description = Custom module description.
package = PACKAGE_NAME (optional)
core = 7.x
files[] = module_name.module
https://snipt.net/embed/7c662cb03f6601c628c952750c373cd0/
/raw/7c662cb03f6601c628c952750c373cd0/
7c662cb03f6601c628c952750c373cd0
php
PHP
5
2019-08-19T00:08:00
True
False
False
/api/public/snipt/36494/
d7-info-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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">name = MODULE_NAME</span> </span><span id="L-2"><a name="L-2"></a><span class="x">description = Custom module description.</span> </span><span id="L-3"><a name="L-3"></a><span class="x">package = PACKAGE_NAME (optional)</span> </span><span id="L-4"><a name="L-4"></a><span class="x">core = 7.x</span> </span><span id="L-5"><a name="L-5"></a><span class="x">files[] = module_name.module</span> </span></pre></div> </td></tr></table>
"drupal 7", "drupal module", .info, d7

PHP

Load a custom menu or submenu in Drupal 7

1
2
3
4
5
6
7
8
// get submenu
$vars['submenu'] = FALSE;
$menu_tree = menu_tree('main-menu'); 
$active_trail = menu_get_active_trail();
$active_trail_mlid = $active_trail[1]['mlid'];
if( array_key_exists($active_trail_mlid, $menu_tree) ) {
  $vars['submenu'] = $menu_tree[$active_trail_mlid]['#below'];	
}
https://snipt.net/embed/e560526180d548c806f6080af510ba79/
/raw/e560526180d548c806f6080af510ba79/
e560526180d548c806f6080af510ba79
php
PHP
8
2019-08-16T05:41:30
True
False
False
/api/public/snipt/36008/
load-a-custom-menu-or-submenu-in-drupal-7
<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> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">// get submenu</span> </span><span id="L-2"><a name="L-2"></a><span class="x">$vars[&#39;submenu&#39;] = FALSE;</span> </span><span id="L-3"><a name="L-3"></a><span class="x">$menu_tree = menu_tree(&#39;main-menu&#39;); </span> </span><span id="L-4"><a name="L-4"></a><span class="x">$active_trail = menu_get_active_trail();</span> </span><span id="L-5"><a name="L-5"></a><span class="x">$active_trail_mlid = $active_trail[1][&#39;mlid&#39;];</span> </span><span id="L-6"><a name="L-6"></a><span class="x">if( array_key_exists($active_trail_mlid, $menu_tree) ) {</span> </span><span id="L-7"><a name="L-7"></a><span class="x"> $vars[&#39;submenu&#39;] = $menu_tree[$active_trail_mlid][&#39;#below&#39;]; </span> </span><span id="L-8"><a name="L-8"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
d7, menu, submenu

PHP

Load author of node and render custom fields from user profile in D7

1
2
3
4
5
6
<?php
// load author
// user this inside of custom node template, e.g. node--blog.tpl.php
$author = user_load($node->uid);
?>
<div class="blog-author-name"><h3>Posted by <?php print $author->field_user_first_name['und'][0]['value'].' '.$author->field_user_last_name['und'][0]['value']; ?></h3></div>
https://snipt.net/embed/39847a535de37041f0e17950e8e00d8e/
/raw/39847a535de37041f0e17950e8e00d8e/
39847a535de37041f0e17950e8e00d8e
php
PHP
6
2019-08-20T16:44:00
True
False
False
/api/public/snipt/35625/
load-author-of-node-and-render-custom-fields-from-user-profile-in-d7
<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><span id="L-2"><a name="L-2"></a><span class="c1">// load author</span> </span><span id="L-3"><a name="L-3"></a><span class="c1">// user this inside of custom node template, e.g. node--blog.tpl.php</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$author</span> <span class="o">=</span> <span class="nx">user_load</span><span class="p">(</span><span class="nv">$node</span><span class="o">-&gt;</span><span class="na">uid</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a><span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-6"><a name="L-6"></a><span class="x">&lt;div class=&quot;blog-author-name&quot;&gt;&lt;h3&gt;Posted by </span><span class="cp">&lt;?php</span> <span class="k">print</span> <span class="nv">$author</span><span class="o">-&gt;</span><span class="na">field_user_first_name</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;value&#39;</span><span class="p">]</span><span class="o">.</span><span class="s1">&#39; &#39;</span><span class="o">.</span><span class="nv">$author</span><span class="o">-&gt;</span><span class="na">field_user_last_name</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;value&#39;</span><span class="p">];</span> <span class="cp">?&gt;</span><span class="x">&lt;/h3&gt;&lt;/div&gt;</span> </span></pre></div> </td></tr></table>
"drupal 7", "user profile", author, node

PHP

Render a content field inside a Node Template. Correct syntax for a field added to a node.

// render a content field inside a Node Template
print render($content['field_NAME_OF_FIELD']);
https://snipt.net/embed/32062154ff962442643fb7469e7a44e7/
/raw/32062154ff962442643fb7469e7a44e7/
32062154ff962442643fb7469e7a44e7
php
PHP
3
2019-08-20T20:47:07
True
False
False
/api/public/snipt/35623/
render-a-content-field-inside-a-node-template-correct-syntax-for-a-field-added-to-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></span><span id="L-1"><a name="L-1"></a><span class="x">// render a content field inside a Node Template</span> </span><span id="L-2"><a name="L-2"></a><span class="x">print render($content[&#39;field_NAME_OF_FIELD&#39;]);</span> </span></pre></div> </td></tr></table>
"drupal 7", "node template", "node theme"

JavaScript

Using Hover Fade jQuery Plugin

1
2
3
4
5
6
7
// Use jQuery Hover Fade Plugin on images
// Plugin here: http://snipt.net/goldhat/hoverfade-jquery-plugin
$('img').hoverfade({
  opacity: 0.5,
  speedFadeOut: 400,
  speedFadeIn: 400
});
https://snipt.net/embed/dec58c75e4fadedd307cc01267b87b10/
/raw/dec58c75e4fadedd307cc01267b87b10/
dec58c75e4fadedd307cc01267b87b10
js
JavaScript
7
2019-08-18T13:23:42
True
False
False
/api/public/snipt/35578/
using-hover-fade-jquery-plugin
<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> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">// Use jQuery Hover Fade Plugin on images</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">// Plugin here: http://snipt.net/goldhat/hoverfade-jquery-plugin</span> </span><span id="L-3"><a name="L-3"></a><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;img&#39;</span><span class="p">).</span><span class="nx">hoverfade</span><span class="p">({</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">opacity</span><span class="o">:</span> <span class="mf">0.5</span><span class="p">,</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">speedFadeOut</span><span class="o">:</span> <span class="mi">400</span><span class="p">,</span> </span><span id="L-6"><a name="L-6"></a> <span class="nx">speedFadeIn</span><span class="o">:</span> <span class="mi">400</span> </span><span id="L-7"><a name="L-7"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
"hover fade plugin", jquery