if ( $catList != NULL )
{
foreach( $catList as $categoryName ) {
foreach( $cats as $blogCategory ) {
$categoryName = trim($categoryName);
if ( strcmp( $categoryName, $blogCategory->getName()) == 0 )
{
$categories[] = $blogCategory->getId();
}
}
}
}
else {
// if no category, let's pick a random one
$blogCategory = array_pop( $cats );
$categories[] = $blogCategory->getId();
}
应该改成:
if ( !empty($catList) )
{
foreach( $catList as $categoryName ) {
foreach( $cats as $blogCategory ) {
$categoryName = trim($categoryName);
if ( strcmp( $categoryName, $blogCategory->getName()) == 0 )
{
$categories[] = $blogCategory->getId();
}
}
}
}
if ( empty($catList) || empty($categories)) {
// if no category, let's pick a random one
$blogCategory = array_pop( $cats );
$categories[] = $blogCategory->getId();
}
否则如果输入的文章分类, 如果不存在的时候, 会发生错误