我是PHP的新手,但希望在wordpress中如何在页面底部显示最新的3篇文章。我希望显示每个帖子的标题,以及属于帖子的图像,也许还有帖子中的第一行文本,带有一个阅读更多按钮,然后我可以使用 CSS 设置样式以匹配网站的其余部分。
这容易实现吗?
感谢您的任何帮助。
检索帖子可以使用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; ?>
试试这个:
$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);
文字新闻参考