2017-06-29 132 views
1

我在函数.php中编写了下面的代码,以便为最新的博客文章创建一个简码。在wordpress中的最新博客文章

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'); 

我怎么可能改变,这样我可以创建短代码, 第2,第3和第4的最新博客文章?如下面的链接中提到的

+0

只是传递参数/ https://developer.wordpress.org/plugins/ shortcodes/shortcodes-with-parameters/ –

回答

2

你也可以使用偏移:

$getpost = get_posts(array('number' => 1, 'offset' => 1)); 
+0

谢谢@Nerijus! –

相关问题