我正在创建shortcode[最新发布]并希望显示发布日期、标题和简短内容。(内容有“更多”分隔符)。以下是代码:
function shortcode_latest_post() {
global $post, $more;
$tmp_post = $post;
$tmp_more = $more;
$posts = get_posts(array(\'numberposts\' => 1, \'post_status\' => \'publish\'));
$output = "";
foreach($posts as $post) {
setup_postdata($post);
$more = 0;
$output .= \'<div class="latest_post">\';
$output .= \'<span class="date">\'. get_the_date() . \'</span>\';
$output .= \'<h3><a href="\'. get_permalink() .\'">\'. get_the_title() .\'</a></h3>\';
$output .= get_the_content("Read more...");
$output .= "</div>";
}
$post = $tmp_post;
$more = $tmp_more;
return $output;
}
add_shortcode("latest_post", "shortcode_latest_post");
但是我对“get\\u the\\u content”函数有问题。它返回全文,而不是短文本和更多链接。
谁能帮帮我吗?
Update:
我找到了解决办法。以上代码已更新。-
http://codex.wordpress.org/Customizing_the_Read_More#How_to_use_Read_More_in_Pages