<? php
// cat est l'ID de colonne showposts est le nombre d'appels
query_posts ('tag=app&cat=1&showposts=1') ;
?>
<ul style="float : left">
<? php if (have _ posts()) :while (have _ posts()) : the _ post() ; ? >
<li>
< a href = » < ? php the_permalink () ? > »><? php the_title() ; ?> </a><! - Titre - >
</li>
<? php endwhile ; endif ; ? >
</ul>
<? php wp_reset_query() ; ?>
Le code ci-dessus est un article avec un id de catégorie étiqueté comme une application dans l'appel. tag, chat, showposts Ces trois attributs ne sont pas tous ajoutés, vous pouvez voir que vous devez ajouter des attributs, si vous voulez également appeler le code d'article avec des images comme suit, mais avant d'ajouter du code, vous devez ajouter dans le modèle de fonction
fonction catch_that_image () {
$post global, $posts ;
$first _ img = » ;
ob _ start () ;
ob _ end _ clean () ;
$output = preg_match_all('/ <img.+ src=['']([^'']+)['].*>/ i', $post-> post _ content, $matches) ;
$first _ img = $matches [1] [0] ;
if(empty($first_img)) { // Définit une image par défaut
$first_img = "/images/default.jpg" ;
}
retourner $first_img ;
}
Après avoir ajouté, le code d'appel est comme suit
<? php
// cat est l'ID de colonne showposts est le nombre d'appels
query_posts('tag=app&showposts=1') ;
?>
<ul style="float : left">
<? php if (have _ posts()) :while (have _ posts()) : the _ post() ; ? >
<li>
< img src = » < ? php echo catch_that_image() ; ?> »alt = "< ? php the_title( ; ?> »width=228px, height=105px/>< ! - Thumbnails - >
< a href = » < ? php the_permalink () ? > »><? php the_title() ; ?> </a><! - Titre - >
</li>
<? php endwhile ; endif ; ? >
</ul>
<? php wp_reset_query() ; ?>