我在functions.php中编写了以下代码,以便创建LATEST博客帖子的简短代码。
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 :(得分:2)
您也可以使用偏移量:
$getpost = get_posts( array('number' => 1, 'offset' => 1) );
答案 1 :(得分:0)
使用下面链接
中提到的using (var fs = File.OpenRead(csvUrl))
using (var reader = new StreamReader(fs, Encoding.UTF8))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if (i > 0)
{
TextFieldParser parser = new TextFieldParser(new StringReader(lineContent));
parser.SetDelimiters(",");
string[] rawFields = parser.ReadFields();
}
}
}
功能
https://developer.wordpress.org/reference/functions/wp_get_recent_posts/#source