Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| webdev:wordpress:query [06/04/2017 12:24] – dolo | webdev:wordpress:query [14/04/2017 10:44] (Version actuelle) – dolo | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | ====== Query, the loop ====== | ||
| + | Référence sur les fonctions et paramètres. | ||
| + | |||
| + | * [[http:// | ||
| + | * [[https:// | ||
| + | |||
| + | Nouvelle query standard : | ||
| + | < | ||
| + | <?php | ||
| + | |||
| + | // The Query | ||
| + | $the_query = new WP_Query( $args ); | ||
| + | |||
| + | // The Loop | ||
| + | if ( $the_query-> | ||
| + | echo '< | ||
| + | while ( $the_query-> | ||
| + | $the_query-> | ||
| + | echo '< | ||
| + | } | ||
| + | echo '</ | ||
| + | /* Restore original Post Data */ | ||
| + | wp_reset_postdata(); | ||
| + | } else { | ||
| + | // no posts found | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Récupérer les posts : https:// | ||
| + | |||
| + | ===== Tri des pages suivant leur slug ===== | ||
| + | < | ||
| + | <? | ||
| + | $pages = get_pages(); | ||
| + | |||
| + | foreach($pages as $page) | ||
| + | { | ||
| + | | ||
| + | { | ||
| + | echo '< | ||
| + | | ||
| + | echo ') no-repeat; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Changer la requête WP_Query ===== | ||
| + | functions.php : | ||
| + | < | ||
| + | // Permet de tirer les posts suivant un champs personnalisé | ||
| + | function my_pre_get_posts( $query ) { | ||
| + | // do not modify queries in the admin | ||
| + | if( is_admin() ) | ||
| + | { | ||
| + | return $query; | ||
| + | } | ||
| + | | ||
| + | if($query-> | ||
| + | { | ||
| + | $query-> | ||
| + | $query-> | ||
| + | $query-> | ||
| + | $query-> | ||
| + | } | ||
| + | // return | ||
| + | return $query; | ||
| + | } | ||
| + | add_action(' | ||
| + | |||
| + | [[https:// | ||