2012-05-07 10 views
0

私はPHPでかなり初心者ですが、Wordpressのページの一番下に最新の3つの投稿を表示する方法についていくつかの援助をしたいと思います。私はポストに属する画像とポストにある画像の最初の行と一緒に表示される各ポストのタイトルを、より多くのボタンを読んで、残りのサイトと一致するようにCSSでスタイルすることができます。PHP Wordpress - 最新の3つの投稿を呼び出す

これは簡単ですか?

ありがとうございました。

答えて

2

を投稿を取得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; ?> 
+0

ありがとう、完璧に働いた。とても有難い。 – malicedix

2

これを試してみてください:

$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); 

Wordpress reference

+0

ありがとう、私はこれも見つけましたが、読み込んだときにエラーが発生したようです。 – malicedix

関連する問題