私は PHP の初心者ですが、wordpress のページの下部に最新の 3 つの投稿を表示する方法を教えてください。各投稿のタイトルと、投稿に属する画像、およびおそらく投稿の最初のテキスト行に、[続きを読む] ボタンを表示して、サイトの残りの部分と一致するように CSS でスタイルを設定できるようにします。
これは簡単に達成できますか?
助けてくれてありがとう。
これを試して:
$args = array(
'numberposts' => 3,
'offset' => 0,
'category' => ,
'orderby' => 'post_date',
'order' => 'DESC',
'include' => ,
'exclude' => ,
'meta_key' => ,
'meta_value' => ,
'post_type' => 'post',
'post_mime_type' => ,
'post_parent' => ,
'post_status' => 'publish' );
get_posts($args);
投稿の取得は次の方法で実行できますget_posts()
:
<?php $posts_array = get_posts( array('numberposts' => 3) ); ?>
投稿のレンダリングに関しては、テーマ(またはインストールされているプラグイン)が何らかの「投稿プレビュー」ウィジェットを提供しているかどうかを確認する価値があります。もしそうなら、いくつかの心痛を保存し、それを使用してください。そうでない場合は、次の行に沿って自分で投稿を印刷できます。
<?php foreach ($posts_array as $post): setup_postdata($post); ?>
<!-- template tag: print thumbnail -->
<?php get_the_post_thumbnail($post->ID); ?>
<!-- template tag: print title -->
<h3><?php the_title(); ?></h3>
<!-- template tag: print excerpt -->
<p><?php the_excerpt(); ?></p>
<?php endforeach; ?>