Created
July 23, 2014 13:37
-
-
Save willybahuaud/1ad49811b8af2cf5abe5 to your computer and use it in GitHub Desktop.
Template de recherche en ajax
This file contains 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 | |
$o = array(); | |
$o[ 'title' ] = wp_title( '', false ); //me sert pour mettre à jour le titre de la fenêtre de navigation | |
$o[ 'type' ] = 'liste'; // le type du template | |
$o[ 'breadcrumb' ] = ffeeeedd__ariane(); //me sert pour mettre à jour le fil d'ariane | |
$q = get_search_query(); | |
if( have_posts() ) : | |
global $wp_query; | |
$f = $wp_query->found_posts; | |
$o[ 'intro' ] = '<div class="grille-intro to-be-added"><h1>' . wp_sprintf( _n( '1 résultat pour la recherche «%2$s»', '%1$d résultats pour la recherche «%2$s»', $f, 'nebula' ), $f, $q ) . '</h1></div>'; | |
$article = '<article class="grille to-be-added">'; | |
while( have_posts() ) : the_post(); | |
if( has_post_thumbnail() ) { | |
$article .= '<a href="' . get_permalink() . '" class="lien-article">'; | |
$c = ( $c = get_comments_number( $post->ID ) ) ? '<div class="comments-number">' . $c . '</div>' : ''; | |
$article .= the_title( '<div class="titre-lien-article"><h2>', '</h2>' . $c . '</div>', false ); | |
$article .= get_the_post_thumbnail( $post->ID, 'article', array( 'class' => 'image-article' ) ); | |
$article .= '<div class="extract-article">'; | |
$article .= wp_trim_words( get_the_excerpt(), 28 ); | |
$article .= '<div class="article-date">' . get_the_time( 'd F Y', $post ) . '</div>'; | |
$article .= get_the_post_thumbnail( $post->ID, 'article', array( 'class' => 'background-image-article' ) ); | |
$article .= '</div>'; | |
$article .= '</a>'; | |
} | |
endwhile; | |
$article .= '</article>'; | |
$o[ 'article' ] = $article; | |
else : | |
$o[ 'intro' ] = '<div class="grille-intro"><h1>' . wp_sprintf( __( 'Aucun résultat pour la recherche «%s»', 'nebula' ), $q ) . '</h1></div>'; | |
endif; | |
if( is_user_logged_in() ) { | |
ob_start(); | |
wp_admin_bar_render(); | |
$o[ 'admin_bar' ] = ob_get_clean(); | |
} | |
echo json_encode( $o ); | |
exit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment