/**
* 截取字符串
*/
function dm_strimwidth($str ,$start , $width ,$trimmarker ){
$output = preg_replace('/^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$start.'}((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$width.'}).*/s','\1',$str);
//上面preg_replace内的为正则表达,俺是菜鸟
return $output.$trimmarker;
}
/**
* 自动生成标题
*/
function creat_status_title( $post_ID ){
if($_POST['post_title'] != '') return;//判断是否有标题,如果有则不用生成
$_POST['post_title'] = dm_strimwidth(strip_tags($_POST['post_content']) ,0 ,12 ,'……' );//截取文章内容从0-12个中文字作为标题,注意一个中文字为两个字符,即为两个英文字母的大小
$my_post = array();
$my_post['ID'] = $post_ID;
$my_post['post_title'] = $_POST['post_title'];
wp_update_post( $my_post );//更新文章标题
}
/**
* 添加钩子
*/
add_action('publish_post', 'creat_status_title', 0);//挂上钩子,即在文章发布、更新的时候执行creat_status_title()函数
/**
* 完结
*/
via:http://wgmcn.com/blog/wordpress/901.html
这个?
不好吧·