El loop WordPress lo utiliza para mostrar cada una de sus publicaciones. Usando The Loop, WordPress procesa cada una de las publicaciones para mostrarlas en la página actual y las formatea según cómo coinciden con los criterios especificados en las etiquetas de The Loop. Normalmente, la cantidad de publicaciones para mostrar se establece en el área de Configuración del panel de administración de WordPress en la pestaña de lectura. Pero en este artículo, le mostraremos cómo anular ese número usando un Super Loop que le permitirá ver cualquier número de publicaciones en ese bucle específico de WordPress. Esto le permitirá personalizar la visualización de sus páginas, incluidos los perfiles de autor, las barras laterales y más.
Abra un archivo de plantilla donde desee colocar las publicaciones y luego simplemente agregue este bucle:
// if everything is in place and ready, let's start the loop <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> // to display 'n' number of posts, we need to execute the loop 'n' number of times // so we define a numerical variable called '$count' and set its value to zero // with each iteration of the loop, the value of '$count' will increase by one // after the value of '$count' reaches the specified number, the loop will stop // *USER: change the 'n' to the number of posts that you would like to display <?php static $count = 0; if ($count == "n") { break; } else { ?> // for CSS styling and layout purposes, we wrap the post content in a div // we then display the entire post content via the 'the_content()' function // *USER: change to '<?php the_excerpt(); ?>' to display post excerpts instead <div class="post"> <?php the_title(); ?> <?php the_content(); ?> </div> // here, we continue with the limiting of the number of displayed posts // each iteration of the loop increases the value of '$count' by one // the final two lines complete the loop and close the if statement <?php $count++; } ?> <?php endwhile; ?> <?php endif; ?>
Y ya está. Este código te será muy útil, especialmente al diseñar la plantilla de autor, porque te gustaría controlar el número de publicaciones que se muestran en cada ciclo.
Fuente: Super Loop para WordPress
¿Te ha resultado útil??
0 / 0