解释我的目标:我将通过记下帖子内容的第一个单词来创建标题。例如:在管理界面中,标题字段为空,创建新帖子时,前10个单词的内容将作为标题发送。
谢谢你的帮助。
解释我的目标:我将通过记下帖子内容的第一个单词来创建标题。例如:在管理界面中,标题字段为空,创建新帖子时,前10个单词的内容将作为标题发送。
谢谢你的帮助。
我写了一个small plugin 就在不久前。它钩住了\'save_post\'
如果没有标题集,则将前20个字符作为标题:
add_action( \'save_post\', \'t5_fix_empty_title\', 11, 2 );
/**
* Fills an empty post title from the first words of the post.
*
* @param int $post_id Post ID
* @param object $post Post object
* @return void
*/
function t5_fix_empty_title( $post_id, $post )
{
if ( ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
or ! current_user_can( \'edit_post\', $post_id )
or ! empty ( $post->post_title )
or empty ( $post->post_content )
or wp_is_post_revision( $post )
)
{ // Noting to do.
return;
}
// Remove all tags and replace breaks whith white space.
$no_tags = wp_strip_all_tags( $post->post_content, TRUE );
// The post content contains just markup.
if ( \'\' === $no_tags )
{
return;
}
$length = apply_filters( \'t5_fix_empty_title_length\', 20 );
$words = preg_split( "/\\s+/", $no_tags, $length, PREG_SPLIT_NO_EMPTY );
array_pop( $words );
$title = implode( \' \', $words );
// Add a no break space and an ellipsis at the end.
$title = rtrim( $title, \'.,!?…*\' ) . \' …\';
wp_update_post( array ( \'ID\' => $post_id, \'post_title\' => $title ) );
}
出于某种原因,我的RSS提要在没有空格的情况下重复了两次站点标题,显然很烦人。BlognameBlogname就是一个例子。有没有什么钩子可以用来定制RSS提要的标题?所以我可以有一个标题“这是我的博客名RSS提要”或任何我想要的?这是可能的,还是我一直在使用这个双重名称。谢谢你的帮助。