首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >wordpress中的最新博客文章

wordpress中的最新博客文章
EN

Stack Overflow用户
提问于 2017-06-29 19:27:13
回答 2查看 45关注 0票数 1

我在下面用functions.php写了这段代码,以便创建一个简短的代码来显示最新的博客文章。

代码语言:javascript
运行
复制
function wptuts_recentpost($atts, $content=null){
$getpost = get_posts( array('number' => 1) );
$getpost = $getpost[0];
$return = $getpost->post_title . "<br />" . $getpost->post_excerpt . "…";
$return .= "<br /><a href='" . get_permalink($getpost->ID) . "'>
<em>read more →</em></a>";
return $return;
}
add_shortcode('newestpost', 'wptuts_recentpost');

我如何改变这一点,以便我可以创建短代码,第二,第三和第四个最新的博客帖子?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-06-29 19:37:38

您还可以使用offset:

代码语言:javascript
运行
复制
$getpost = get_posts( array('number' => 1, 'offset' => 1) );
票数 2
EN

Stack Overflow用户

发布于 2017-06-29 19:33:43

使用以下链接中提到的wp_get_recent_posts函数

https://developer.wordpress.org/reference/functions/wp_get_recent_posts/#source

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44823848

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档