<? ph p
/ / cat ist die Kol um nen - ID und show pos ts ist die Auf ruf nummer .
quer y _ pos ts (' tag = app & cat = 1 & s how pos ts = 1 ');
?>
< ul style = " flo at : le ft " >
<? ph p if (have _ posts ()) : w hile (have _ posts ()) : the _ post (); ? >
<li>
< a h ref = " < ? ph p the _ per mal ink () ? > > ><? ph p the _ tit le (); ? > </a><! Titel - >
</li>
<? ph p end w hile ; endi f ; ? >
</ul>
<? ph p wp _ res et _ quer y (); ? >
Der obi ge Code ru ft einen Artikel mit der Kateg orie ID 1 in der Tag ung App auf . tag , cat , show pos ts Diese drei Att ribu te müssen nicht alle hin zug ef ü gt werden , können Sie sehen , dass Sie Att ribu te hin zu fü gen müssen , wenn Sie den Artikel code mit einem Bild wie folgt auf ru fen mö chten , aber bevor Sie den Code hin zu fü gen müssen Sie es in die Funk tions vor lage hin zu fü gen
Funk tion catch _ that _ image () {
global $post , $pos ts ;
$fir st _ im g = » ;
ob _ start () ;
ob _ end _ clean () ;
$out put = preg _ mat ch _ all ('/ < im g .+ sr c = [ ' ' ] ([ ^ ' ' ] + ] [ ' ]. * >/ i ' , $post - > post _ content , $mat ches);
$fir st _ im g = $mat ches [1] [ 0 ];
if (emp ty ($fir st _ im g)) {//De fini ert ein Standard bild
$first_img = "/images/default.jpg"
}
return $fir st _ im g ;
}
Nach dem Hinzufügen, rufen Sie den Code wie folgt auf:
<? ph p
/ / cat ist die Kol um nen - ID und show pos ts ist die Auf ruf nummer .
query_posts('tag=app&showposts=1');
?>
< ul style = " flo at : le ft " >
<? ph p if (have _ posts ()) : w hile (have _ posts ()) : the _ post (); ? >
<li>
< img src = » <? php echo catch_that_image();?> alt = "<? php the_title();?> »width="228px", height="105px"/><! - Miniatur - >
< a h ref = " < ? ph p the _ per mal ink () ? > > ><? ph p the _ tit le (); ? > </a><! Titel - >
</li>
<? ph p end w hile ; endi f ; ? >
</ul>
<? ph p wp _ res et _ quer y (); ? >