1
是否有可能抓住所见即所得编辑器的内容并自动将前100个单词保存到摘录中?我知道excerpt_save_pre
可以在编辑器中保存摘录,但没有看到任何可以从WYSIWYG编辑器获取内容的内容。自动摘录所见即所得
是否有可能抓住所见即所得编辑器的内容并自动将前100个单词保存到摘录中?我知道excerpt_save_pre
可以在编辑器中保存摘录,但没有看到任何可以从WYSIWYG编辑器获取内容的内容。自动摘录所见即所得
我已经想通了。帖子保存/发布时,“秘密”为&$_POST
。构建一个数组,内容可以被提取,然后使用excerpt_save_pre
保存到摘录字段。
我去了的字符数或词的数量稍微进一步允许控制,采用$length
,并且输出被控制在其上$output
部你取消注释。
下面的代码在我的香草网站上测试过。
function auto_insert_excerpt(){
$post_data = &$_POST;
$post_content = $post_data['content'];
$length = 15;
// This will return the first $length number of CHARACTERS
//$output = (strlen($post_content) > 13) ? substr($post_content,0,$length).'...' : $post_content;
// This will return the first $length number of WORDS
$post_content_array = explode(' ',$post_content);
if(count($post_content_array) > $length && $length > 0)
$output = implode(' ',array_slice($post_content_array, 0, $length)).'...';
return $output;
}
add_filter('excerpt_save_pre', 'auto_insert_excerpt');
你为什么试图抓住所见即所得的编辑器的内容?当你保存你的文章时,WordPress可以自动创建一个特定长度的摘录(你可以在设置菜单中调整)。 – MeRuud 2013-04-04 19:25:10
好点。我刚刚发现了一些使用'&$ _ POST'的内容,并且正在从中获取内容。 – Pat 2013-04-04 19:29:21