Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

PHP

Wordpress: Search form on specific custom type

1
2
3
4
5
6
7
<form method="get" id="searchform" class="searchform" action="<?php bloginfo('home'); ?>/">
    <div class="input-append">
        <input type="hidden" name="post_type" value="event" /> <?php // This does the trick, search only on post type named "event" ?>
        <input type="text" class="span2 field" name="s" id="s" placeholder="Search" value="<?php echo wp_specialchars($s, 1); ?>" >
        <input type="submit" class="btn" name="submit" id="searchsubmit" value="OK">
    </div>
</form>
https://snipt.net/embed/125651205cb8326e51e03fe6ad9bbafb/
https://snipt.net/raw/125651205cb8326e51e03fe6ad9bbafb/
125651205cb8326e51e03fe6ad9bbafb
php
PHP
7
2016-12-03T09:16:41
True
False
True
Jan 14, 2013 at 06:24 AM
/api/public/snipt/53682/
wordpress-search-form-on-specific-custom-type
<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="x">&lt;form method=&quot;get&quot; id=&quot;searchform&quot; class=&quot;searchform&quot; action=&quot;</span><span class="cp">&lt;?php</span> <span class="nx">bloginfo</span><span class="p">(</span><span class="s1">&#39;home&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="x">/&quot;&gt;</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> &lt;div class=&quot;input-append&quot;&gt;</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> &lt;input type=&quot;hidden&quot; name=&quot;post_type&quot; value=&quot;event&quot; /&gt; </span><span class="cp">&lt;?php</span> <span class="c1">// This does the trick, search only on post type named &quot;event&quot; ?&gt;</span> </span><span id="L-4"><a name="L-4"></a> <span class="o">&lt;</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">&quot;text&quot;</span> <span class="nx">class</span><span class="o">=</span><span class="s2">&quot;span2 field&quot;</span> <span class="nx">name</span><span class="o">=</span><span class="s2">&quot;s&quot;</span> <span class="nx">id</span><span class="o">=</span><span class="s2">&quot;s&quot;</span> <span class="nx">placeholder</span><span class="o">=</span><span class="s2">&quot;Search&quot;</span> <span class="nx">value</span><span class="o">=</span><span class="s2">&quot;&lt;?php echo wp_specialchars(</span><span class="si">$s</span><span class="s2">, 1); ?&gt;&quot;</span> <span class="o">&gt;</span> </span><span id="L-5"><a name="L-5"></a> <span class="o">&lt;</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">&quot;submit&quot;</span> <span class="nx">class</span><span class="o">=</span><span class="s2">&quot;btn&quot;</span> <span class="nx">name</span><span class="o">=</span><span class="s2">&quot;submit&quot;</span> <span class="nx">id</span><span class="o">=</span><span class="s2">&quot;searchsubmit&quot;</span> <span class="nx">value</span><span class="o">=</span><span class="s2">&quot;OK&quot;</span><span class="o">&gt;</span> </span><span id="L-6"><a name="L-6"></a> <span class="o">&lt;/</span><span class="nx">div</span><span class="o">&gt;</span> </span><span id="L-7"><a name="L-7"></a><span class="o">&lt;/</span><span class="nx">form</span><span class="o">&gt;</span> </span></pre></div> </td></tr></table>
custom, search, type, wordpress

Text only

WordPress Permalinks Best Practice 2

/%category%/%postname%/%post_id%/
https://snipt.net/embed/9923e706208c0b9f2ebfc5902fc8b09d/
https://snipt.net/raw/9923e706208c0b9f2ebfc5902fc8b09d/
9923e706208c0b9f2ebfc5902fc8b09d
text
Text only
1
2016-12-09T16:04:01
True
False
False
/api/public/snipt/32515/
wordpress-permalinks-best-practice-2
<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></span><span id="L-1"><a name="L-1"></a>/%category%/%postname%/%post_id%/ </span></pre></div> </td></tr></table>
custom, post, type

Python

Check object type of var.

1
2
3
4
if isinstance(varname, float):
    # Do this
else:
    # Do that
https://snipt.net/embed/5ba94b57d7fb23ae7409d7a0eb6314c4/
https://snipt.net/raw/5ba94b57d7fb23ae7409d7a0eb6314c4/
5ba94b57d7fb23ae7409d7a0eb6314c4
python
Python
5
2016-12-08T18:19:24
True
False
False
/api/public/snipt/21182/
check-object-type-of-var
<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></span><span id="L-1"><a name="L-1"></a><span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">varname</span><span class="p">,</span> <span class="nb">float</span><span class="p">):</span> </span><span id="L-2"><a name="L-2"></a> <span class="c1"># Do this</span> </span><span id="L-3"><a name="L-3"></a><span class="k">else</span><span class="p">:</span> </span><span id="L-4"><a name="L-4"></a> <span class="c1"># Do that</span> </span></pre></div> </td></tr></table>
object, python, type

CSS

kerning type css

/* kerning and readability improvement in Safari and Chrome */
html { text-rendering: optimizeLegibility; }
https://snipt.net/embed/fd91d479681667692e939b29faf85e8a/
https://snipt.net/raw/fd91d479681667692e939b29faf85e8a/
fd91d479681667692e939b29faf85e8a
css
CSS
2
2016-12-09T16:05:07
True
False
False
/api/public/snipt/16142/
kerning-type-css
<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="c">/* kerning and readability improvement in Safari and Chrome */</span> </span><span id="L-2"><a name="L-2"></a><span class="nt">html</span> <span class="p">{</span> <span class="nb">text</span><span class="o">-</span><span class="n">rendering</span><span class="o">:</span> <span class="n">optimizeLegibility</span><span class="p">;</span> <span class="p">}</span> </span></pre></div> </td></tr></table>
css, css3, type, webkit

PHP

Retourne le type mime d'un fichier

1
2
3
<?
$fileType = mime_content_type($pathToFile);
?>
https://snipt.net/embed/b9c32076c0fdf10d4eb53354059730e3/
https://snipt.net/raw/b9c32076c0fdf10d4eb53354059730e3/
b9c32076c0fdf10d4eb53354059730e3
php
PHP
3
2016-12-09T12:28:50
True
False
False
/api/public/snipt/4262/
retourne-le-type-mime-dun-fichier
<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></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;?</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$fileType</span> <span class="o">=</span> <span class="nb">mime_content_type</span><span class="p">(</span><span class="nv">$pathToFile</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
fichier, file, mime, type
Copyrighted, illegal, or inappropriate content? Email [email protected].