Skip to content

Instantly share code, notes, and snippets.

@AndreaBarghigiani
Created January 1, 2018 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreaBarghigiani/1ce14a2423016d0bd099409d586f03ff to your computer and use it in GitHub Desktop.
Save AndreaBarghigiani/1ce14a2423016d0bd099409d586f03ff to your computer and use it in GitHub Desktop.
In questo Gist si trovano tutti i codici necessari alla realizzazione e gestione di un Loop WordPress tramite WP_Query. Trovi tutta la descrizione all'interno del seguente articolo:
<?php //Apertura PHP inserita solo per colorazione sintassi
//Inizializzazione oggetto WP_Query
$loop = new WP_Query( array( 'cat' => 3 ) );
<?php //Apertura PHP inserita solo per colorazione sintassi
//Configurazione standard WP_Query
$args = array(
'cat' => 3
);
$loop = new WP_Query( $args );
<?php //Apertura PHP inserita solo per colorazione sintassi
//Array di configurazione Loop
$args = array(
'cat' => 3
);
$loop = new WP_Query( $args );
if( $loop->have_posts() ) :
while( $loop->have_posts() ) : $loop->the_post();
?>
<!-- Cosa fare dentro il loop -->
<?php
endwhile;
else:
?>
<!-- Cosa fare se il loop non trova niente -->
<?php
endif;
wp_reset_query();
?>
<?php //Apertura PHP inserita solo per colorazione sintassi
//Creazione di 3 Loop nella stessa pagina
$args = array( 'cat' => 3 );
$loop_cat1 = new WP_Query( $args );
if( $loop_cat1->have_posts() ) :
while( $loop_cat1->have_posts() ) : $loop_cat1->the_post();
?>
<!-- Cosa fare dentro il loop -->
<?php
endwhile;
else:
?>
<!-- Cosa fare se il loop non trova niente -->
<?php
endif;
wp_reset_query();
$args2 = array( 'cat' => 5 );
$loop_cat2 = new WP_Query( $args2 );
if( $loop_cat2->have_posts() ) :
while( $loop_cat2->have_posts() ) : $loop_cat2->the_post();
?>
<!-- Cosa fare dentro il loop -->
<?php
endwhile;
else:
?>
<!-- Cosa fare se il loop non trova niente -->
<?php
endif;
wp_reset_query();
$args3 = array( 'cat' => 11 );
$loop_cat3 = new WP_Query( $args3 );
if( $loop_cat3->have_posts() ) :
while( $loop_cat3->have_posts() ) : $loop_cat3->the_post();
?>
<!-- Cosa fare dentro il loop -->
<?php
endwhile;
else:
?>
<!-- Cosa fare se il loop non trova niente -->
<?php
endif;
wp_reset_query();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment