-2
A
回答
1
<?php
function latest_post() {
$args = array(
'posts_per_page' => 3, /* how many post you need to display */
'offset' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post', /* your post type name */
'post_status' => 'publish'
);
$query = new WP_Query($args);
if ($query->have_posts()) :
while ($query->have_posts()) : $query->the_post();
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php echo get_the_post_thumbnail('thumbnail'); ?>
/* here add code what you need to display like above title, image and more */
<?php
endwhile;
endif;
}
add_shortcode('lastest-post', 'latest_post');
?>
- 加入上面的代码function.php文件。
- 之后,粘贴shortcode下面你想显示最新的帖子。
- 埃丁侧:最新的-交]
- 在文件:
<?php echo do_shortcode('[lastest-post]'); ?>
0
<?php
//Query 3 recent published post in descending order
$args = array('numberposts' => '3', 'order' => 'DESC','post_status' => 'publish');
$recent_posts = wp_get_recent_posts($args);
//Now lets do something with these posts
foreach($recent_posts as $recent)
{
echo 'Post ID: '.$recent["ID"];
echo 'Post URL: '.get_permalink($recent["ID"]);
echo 'Post Title: '.$recent["post_title"];
//Do whatever else you please with this WordPress post
}
?>
相关问题
- 1. wordpress如何显示最近更新的页面和帖子
- 2. 如何在Wordpress中的循环外显示最新的帖子?
- 3. 如何在wordpress中显示最新帖子的图片
- 4. 如何在其他网站上显示WordPress的最新帖子?
- 5. 最新帖子if else - wordpress
- 6. WordPress最新帖子轮播
- 7. 如何显示WordPress的帖子摘录?
- 8. WordPress的显示帖子
- 9. 显示帖子 - WordPress的
- 10. WordPress的帖子不显示
- 11. 显示最新的帖子来自wordpress中的指定类别
- 12. 显示wordpress中最新分类标准的所有帖子
- 13. WordPress的 - 静态首页应该显示最新帖子
- 14. WordPress的:如何显示最受好评的帖子?
- 15. 如何显示默认帖子时显示自定义帖子wordpress?
- 16. 如何在未运行wordpress的子域上显示WordPress帖子?
- 17. Rails显示帖子最新评论
- 18. 从帖子到帖子在Wordpress循环页面显示所有帖子显示
- 19. 显示每个帖子类型的最新帖子
- 20. Rails:显示除最新帖子外的所有帖子
- 21. 如何在wordpress中显示自定义帖子类型的每个类别的最新帖子
- 22. WordPress:防止显示子类别帖子
- 23. 如何在博客应用上显示最新帖子?
- 24. 如何显示5个最新帖子的所有月份?
- 25. WordPresspress:显示来自不同WordPress网站(子域)的最新帖子
- 26. WordPress的帖子最后的帖子
- 27. 最新帖子bootstrap网格wordpress
- 28. 拉最新论坛WordPress内的帖子
- 29. Wordpress - 强制最新帖子第一
- 30. WordPress的最新帖子精选图像