snipt

Ctrl+h for KB shortcuts

PHP

Basic Wordpress Loop

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


<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
https://snipt.net/embed/99701b047aa99f02d82e462612f20cd2/
/raw/99701b047aa99f02d82e462612f20cd2/
99701b047aa99f02d82e462612f20cd2
php
PHP
7
2019-05-23T18:43:42
True
False
False
/api/public/snipt/45776/
basic-wordpress-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> <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="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 class="x"></span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></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 class="x"></span> </span><span id="L-5"><a name="L-5"></a><span class="x">&lt;p&gt;</span><span class="cp">&lt;?php</span> <span class="nx">_e</span><span class="p">(</span><span class="s1">&#39;Sorry, no posts matched your criteria.&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="x">&lt;/p&gt;</span> </span><span id="L-6"><a name="L-6"></a><span class="cp">&lt;?php</span> <span class="k">endif</span><span class="p">;</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
Loop, Wordpress