<? PHPは
//catは列ID showpostsは呼び出し番号
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><!タイトル
</li>
<? php endwhile; endif;>
</ul>
<? php wp_reset_;>
上記のコードは、カテゴリIDが1にアプリを持つ記事を呼び出しています。tag、cat、showpostsこれらの3つのプロパティはすべて追加する必要はありません。次のように画像付きの記事コードを呼び出したい場合は、プロパティを追加する必要がありますが、コードを追加する前に関数テンプレートに追加する必要があります。
function catch_that_image {
al $post
$first_img =";
ob_start ob_start nParticle nParticle;
_end_clean
$output = preg_match_all/<img.+ src=[][^']+[].*>/ i $post->post_content $matches;
$first_img = $マッチ[1] [0];
if empty $first_img { //default imageの定義
$first_img = “/images/default.jpg”;
}
$first_imgを返す
}
追加後のコードは以下の通りです。
<? PHPは
//catは列ID showpostsは呼び出し番号
_posts
?>
<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/><!サムネール
<a href=< php the_permalink> ><? php the_title;> </a><!タイトル
</li>
<? php endwhile; endif;>
</ul>
<? php wp_reset_;>