snipt

Ctrl+h for KB shortcuts

PHP

Wordpress: Loop de noticias en cualquier página

1
2
3
4
5
6
7
<?php $my_query = "showposts=3&cat=5"; $my_query = new WP_Query($my_query); ?>
<?php if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>

<!-- Insert the regular template tags you would use within the loop here-->

<?php endwhile; // end of one post ?>
<?php endif; //end of loop ?>
https://snipt.net/embed/3ba26c1cda152acfa41538d560851ae8/
/raw/3ba26c1cda152acfa41538d560851ae8/
3ba26c1cda152acfa41538d560851ae8
php
PHP
7
2019-07-16T08:47:31
True
False
False
Sep 20, 2012 at 03:38 PM
/api/public/snipt/45027/
wordpress-loop-de-noticias-en-cualquier-pagina
<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="nv">$my_query</span> <span class="o">=</span> <span class="s2">&quot;showposts=3&amp;cat=5&quot;</span><span class="p">;</span> <span class="nv">$my_query</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">WP_Query</span><span class="p">(</span><span class="nv">$my_query</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 class="cp">&lt;?php</span> <span class="k">if</span> <span class="p">(</span><span class="nv">$my_query</span><span class="o">-&gt;</span><span class="na">have_posts</span><span class="p">())</span> <span class="o">:</span> <span class="k">while</span> <span class="p">(</span><span class="nv">$my_query</span><span class="o">-&gt;</span><span class="na">have_posts</span><span class="p">())</span> <span class="o">:</span> <span class="nv">$my_query</span><span class="o">-&gt;</span><span class="na">the_post</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="x">&lt;!-- Insert the regular template tags you would use within the loop here--&gt;</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="cp">&lt;?php</span> <span class="k">endwhile</span><span class="p">;</span> <span class="c1">// end of one post ?&gt;</span> </span><span id="L-7"><a name="L-7"></a><span class="o">&lt;?</span><span class="nx">php</span> <span class="k">endif</span><span class="p">;</span> <span class="c1">//end of loop ?&gt;</span> </span></pre></div> </td></tr></table>
loop, page, wordpress