2017-05-12 16 views
-1

私は自分のウェブサイトを作成するためにwordpressを使用しています。フロントページには最新の2つのブログ投稿と最新の2つのニュース記事を表示したいと思います。 表示するテキストの例はそのようなものです:wordpressを使用して、フロントページに最新のニュースとブログの投稿を表示するには?

<div class="blog_bloc"> 
<span class="Title_post">Title</span> 
<p class="text_post">blog post text text text text text</p> 
<button id="read" > 
Read more 
</button><br><br> 
<span class="Title_post">Title</span> 
<p class="text_post">blog post text text text text text</p> 
<button id="read" > 
Read more 
</button> 
</div> 

私は私がブログページやニュースのページから最新の投稿や記事を表示するpage.Nowブログページやニュースを作成するためのワードプレスでいくつかのプラグインを見つけましたフロントページに自動的に入れます。私のテンプレートに最新の記事をスクラップしてフロントページに自動的に入れるプラグインがありますか?最新の投稿を取得するには

+0

あなたは何を試しましたか? – Siyah

+0

私はテンプレートのファイル投稿ページ(home.php)を見つけました。記事のタイトルとテキストを表示するためにそれをフォローしようとしましたが無駄はありませんでした。 –

答えて

0

はこのPHPの関数を使用する:

<?php 
$args = array(
    'numberposts' => 10, 
    'offset' => 0, 
    'category' => 0, 
    'orderby' => 'post_date', 
    'order' => 'DESC', 
    'include' => '', 
    'exclude' => '', 
    'meta_key' => '', 
    'meta_value' =>'', 
    'post_type' => 'post', 
    'post_status' => 'draft, publish, future, pending, private', 
    'suppress_filters' => true 
); 

$recent_posts = wp_get_recent_posts($args, ARRAY_A); 
?> 

これはどのあなたは、2件の最新の投稿を表示するには、をループすることができます配列を返します。

サンプルスクリプトは次のようになります。

<?php 
$args = array(
    'numberposts' => 2, 
); 

$recent_posts = wp_get_recent_posts($args); 


foreach ($recent_posts as $post) { 

?> 

<div class="blog_bloc"> 
    <span class="Title_post"><?php echo $post["post_title"]; ?></span> 
    <button id="read" > 
    Read more 
    </button> 
</div> 

<?php 

} 

wp_reset_query(); 

?> 
+0

私はこのプログラムをHTMLページに入れましたか? –

+0

動的コンテンツのPHPページを使用する必要があります – Tobi

+0

WordPressが投稿を表示するためにいくつかのファイルと関数を使用していて、必要なものを表示するためにコードを使用する方法が見つかりませんでした。 –

0

それは通常、ホームページまたは任意の場所に5件の投稿が表示されます。

// Define our WP Query Parameters 
<?php $the_query = new WP_Query('posts_per_page=5'); ?> 

// Start our WP Query 
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> 

// Display the Post Title with Hyperlink 
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a> 

// Display the Post Excerpt 
<?php the_excerpt(__('(more…)')); ?> 

// Repeat the process and reset once it hits the limit 
<?php 
endwhile; 
wp_reset_postdata(); 
?> 

独自のCSSを使用してください。

+0

申し訳ありませんが、私にとってはうまくいかなかった:/ –

関連する問題