snipt

Ctrl+h for KB shortcuts

PHP

Wordpress: Mostrar solo ultimo post en Index

<?php /* Antes del loop */
$i=0; if (have_posts()) : while (have_posts()) : the_post(); if ($i==0) {$recentpostid = $post->ID; $i=$i+1;} endwhile; endif;  $posts = query_posts( 'p='.$recentpostid."'"); ?>
https://snipt.net/embed/c9f1e2e2b3c9f79f48edcef0bc33332b/
https://snipt.net/raw/c9f1e2e2b3c9f79f48edcef0bc33332b/
c9f1e2e2b3c9f79f48edcef0bc33332b
php
PHP
2
2016-09-24T03:47:48
True
False
False
/api/public/snipt/42183/
wordpress-mostrar-solo-ultimo-post-en-index
<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 id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="cm">/* Antes del loop */</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$i</span><span class="o">=</span><span class="mi">0</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="k">if</span> <span class="p">(</span><span class="nv">$i</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span> <span class="p">{</span><span class="nv">$recentpostid</span> <span class="o">=</span> <span class="nv">$post</span><span class="o">-&gt;</span><span class="na">ID</span><span class="p">;</span> <span class="nv">$i</span><span class="o">=</span><span class="nv">$i</span><span class="o">+</span><span class="mi">1</span><span class="p">;}</span> <span class="k">endwhile</span><span class="p">;</span> <span class="k">endif</span><span class="p">;</span> <span class="nv">$posts</span> <span class="o">=</span> <span class="nx">query_posts</span><span class="p">(</span> <span class="s1">&#39;p=&#39;</span><span class="o">.</span><span class="nv">$recentpostid</span><span class="o">.</span><span class="s2">&quot;&#39;&quot;</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
index, post, single, wordpress
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.