Verfahren Entwicklung

WordPress teilt einen Artikel mit Code.

<? ph p //cat ist die Kol um nen - ID show pos ts ist die Auf ruf nummer quer y _ pos ts (' t [...]

Artikel Ver zeich nis

<? 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>
&lt; a h ref = " &lt; ? ph p the _ per mal ink () ? &gt; &gt; ><? ph p the _ tit le (); ? &gt; </a>&lt;! Titel - &gt;
</li>
<? ph p end w hile ; endi f ; ? &gt;
</ul>
<? ph p wp _ res et _ quer y (); ? &gt;

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 ('/ &lt; im g .+ sr c = [ ' ' ] ([ ^ ' ' ] + ] [ ' ]. * &gt;/ i ' , $post - &gt; 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 - >
&lt; a h ref = " &lt; ? ph p the _ per mal ink () ? &gt; &gt; ><? ph p the _ tit le (); ? &gt; </a>&lt;! Titel - &gt;
</li>
<? ph p end w hile ; endi f ; ? &gt;
</ul>
<? ph p wp _ res et _ quer y (); ? &gt;