Created
January 1, 2018 18:25
-
-
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:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Apertura PHP inserita solo per colorazione sintassi | |
//Inizializzazione oggetto WP_Query | |
$loop = new WP_Query( array( 'cat' => 3 ) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Apertura PHP inserita solo per colorazione sintassi | |
//Configurazione standard WP_Query | |
$args = array( | |
'cat' => 3 | |
); | |
$loop = new WP_Query( $args ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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