プログラムの開発

Word Pressはカテゴリ記事コード共有を呼び出す

<? php //catはカラムID showpostsは呼び出し数query_posts t []

記事の目次

<? 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>
&lt;a href=&lt; php the_permalink&gt; ><? php the_title;&gt; </a>&lt;!タイトル
</li>
<? php endwhile; endif;&gt;
</ul>
<? php wp_reset_;&gt;

上記のコードは、カテゴリ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/&lt;img.+ src=[][^']+[].*&gt;/ i $post-&gt;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/><!サムネール
&lt;a href=&lt; php the_permalink&gt; ><? php the_title;&gt; </a>&lt;!タイトル
</li>
<? php endwhile; endif;&gt;
</ul>
<? php wp_reset_;&gt;