私はindex.phpファイルの異なる場所に10個のコンテナがある静的なページを持っています。最新の10個の記事を表示したいのですが。私はこのようなポストのためのデータ(タイトル、テキスト、サムネイル、作者、時間)をエコーしたい: Wordpressの最新の投稿
<div class="text">
<?php
echo '$textfrompost3';
?>
</div>
<div class="title">
<?php
echo '$titlefrompost3';
?>
</div>
...
...
私のPHPファイル
:事前に<?php
// the query
$the_query = new WP_Query(array(
'category_name' => 'Allgemein',
'posts_per_page' => 10,
"orderby" => "date",
"order" => "DESC"
));
?>
<?php if ($the_query->have_posts()) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
// insert values into variables
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
おかげで、私は任意のヘルプあなたに感謝します提供することができます。
可能な複製を(HTTP :/ /stackoverflow.com/questions/41631565/how-to-display-latest-posts-wordpress) –
は、ループ内のお互いの直下にある投稿を印刷しているため、変数または何か他のもの –
これを試してみてください。 https://wordpress.stackexchange.com/questions/217299/wp-query-results-stored-in-variables-「変数にWP_QUERYの結果を取得する」と検索したときにGoogleが返したもの –