Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Java Server Page

Breaking JSTL ForEach Loop

1
2
3
4
5
<c:forEach items="${items[id]}" var="doc" varStatus="status">
    <c:if test="${item.ready}">
        <c:set var="status.index" value="${items.size}"/>
    </c:if>
</c:forEach>
https://snipt.net/embed/ff9830b24164c4b59402fde646b352f4/
https://snipt.net/raw/ff9830b24164c4b59402fde646b352f4/
ff9830b24164c4b59402fde646b352f4
jsp
Java Server Page
5
2016-12-05T16:17:16
True
False
False
/api/public/snipt/66139/
breaking-jstl-foreach-loop
<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="nt">&lt;c:forEach</span> <span class="na">items=</span><span class="s">&quot;${items[id]}&quot;</span> <span class="na">var=</span><span class="s">&quot;doc&quot;</span> <span class="na">varStatus=</span><span class="s">&quot;status&quot;</span><span class="nt">&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="nt">&lt;c:if</span> <span class="na">test=</span><span class="s">&quot;${item.ready}&quot;</span><span class="nt">&gt;</span> </span><span id="L-3"><a name="L-3"></a> <span class="nt">&lt;c:set</span> <span class="na">var=</span><span class="s">&quot;status.index&quot;</span> <span class="na">value=</span><span class="s">&quot;${items.size}&quot;</span><span class="nt">/&gt;</span> </span><span id="L-4"><a name="L-4"></a> <span class="nt">&lt;/c:if&gt;</span> </span><span id="L-5"><a name="L-5"></a><span class="nt">&lt;/c:forEach&gt;</span> </span></pre></div> </td></tr></table>
jsp, jstl, loop

Text only

if article is tagged gites-de-france, show image in loop

1
2
3
<?php if ( has_tag( 'gites-de-france' ) ) {
    echo '<img src="img-path.png" alt="xxx" title="x">';
}  ?>
https://snipt.net/embed/656d0e0f075785b7c9e7eed7a1e09a63/
https://snipt.net/raw/656d0e0f075785b7c9e7eed7a1e09a63/
656d0e0f075785b7c9e7eed7a1e09a63
text
Text only
3
2016-12-04T12:13:21
True
False
False
Jun 13, 2013 at 06:25 AM
/api/public/snipt/64071/
if-article-is-tagged-gites-de-france-show-image-in-loop
<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>&lt;?php if ( has_tag( &#39;gites-de-france&#39; ) ) { </span><span id="L-2"><a name="L-2"></a> echo &#39;&lt;img src=&quot;img-path.png&quot; alt=&quot;xxx&quot; title=&quot;x&quot;&gt;&#39;; </span><span id="L-3"><a name="L-3"></a>} ?&gt; </span></pre></div> </td></tr></table>
"image for tag", loop, wordpress

PHP

Query: mostrar posts de una taxonomía dinámicamente

<?php query_posts( array( 'post_type' => 'POSTTYPE', 'taxonomy'=>'TAXONOMIA', 'term'=>$term->slug )); if (have_posts()) :  while (have_posts()) : the_post(); ?>
https://snipt.net/embed/1fad744fbc3d8d99f09dae47e3a10d65/
https://snipt.net/raw/1fad744fbc3d8d99f09dae47e3a10d65/
1fad744fbc3d8d99f09dae47e3a10d65
php
PHP
1
2016-12-02T15:01:28
True
False
False
Jan 25, 2013 at 08:42 AM
/api/public/snipt/54457/
query-mostrar-posts-de-una-taxonomia-dinamicamente
<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><span class="cp">&lt;?php</span> <span class="nx">query_posts</span><span class="p">(</span> <span class="k">array</span><span class="p">(</span> <span class="s1">&#39;post_type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;POSTTYPE&#39;</span><span class="p">,</span> <span class="s1">&#39;taxonomy&#39;</span><span class="o">=&gt;</span><span class="s1">&#39;TAXONOMIA&#39;</span><span class="p">,</span> <span class="s1">&#39;term&#39;</span><span class="o">=&gt;</span><span class="nv">$term</span><span class="o">-&gt;</span><span class="na">slug</span> <span class="p">));</span> <span class="k">if</span> <span class="p">(</span><span class="nx">have_posts</span><span class="p">())</span> <span class="o">:</span> <span class="k">while</span> <span class="p">(</span><span class="nx">have_posts</span><span class="p">())</span> <span class="o">:</span> <span class="nx">the_post</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"custom post type", loop, taxonomia, wordpress

HTML+PHP

basic loop wordpress /

1
2
3
4
5
6
7
	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

	<?php endwhile; else: ?>
	<!-- Texto a mostrar si no existe ning&uacute;n Post -->
	<div>Lo sentimos :( No tenemos ning&uacute;n post para mostrar.</div>

	<?php endif; ?>
https://snipt.net/embed/5056d9d8b4ad4e05126cd80ab285cb60/
https://snipt.net/raw/5056d9d8b4ad4e05126cd80ab285cb60/
5056d9d8b4ad4e05126cd80ab285cb60
html+php
HTML+PHP
7
2016-12-05T15:36:45
True
False
False
/api/public/snipt/54361/
basic-loop-wordpress
<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="cp">&lt;?php</span> <span class="k">if</span> <span class="p">(</span> <span class="nx">have_posts</span><span class="p">()</span> <span class="p">)</span> <span class="o">:</span> <span class="k">while</span> <span class="p">(</span> <span class="nx">have_posts</span><span class="p">()</span> <span class="p">)</span> <span class="o">:</span> <span class="nx">the_post</span><span class="p">();</span> <span class="cp">?&gt;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a> <span class="cp">&lt;?php</span> <span class="k">endwhile</span><span class="p">;</span> <span class="k">else</span><span class="o">:</span> <span class="cp">?&gt;</span> </span><span id="L-4"><a name="L-4"></a> <span class="c">&lt;!-- Texto a mostrar si no existe ning&amp;uacute;n Post --&gt;</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">&lt;</span><span class="nt">div</span><span class="p">&gt;</span>Lo sentimos :( No tenemos ning<span class="ni">&amp;uacute;</span>n post para mostrar.<span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a> <span class="cp">&lt;?php</span> <span class="k">endif</span><span class="p">;</span> <span class="cp">?&gt;</span> </span></pre></div> </td></tr></table>
loop, wordpress
Copyrighted, illegal, or inappropriate content? Email [email protected].