
实例说明如何通过Python来连接管理WordPress
separate_comments ( $comments )
separate_comments: 这是一个WordPress的函数,它根据评论的类型将其分离成不同的数组。它通常被用来分别显示评论和回帖,并定制每种类型的输出: 这个函数有一个参数,就是要分离的评论数组。
将一个评论数组分离成一个以comment_type为关键字的数组。
function separate_comments( &$comments ) { $comments_by_type = array( 'comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array(), ); $count = count( $comments ); for ( $i = 0; $i < $count; $i++ ) { $type = $comments[ $i ]->comment_type; if ( empty( $type ) ) { $type = 'comment'; } $comments_by_type[ $type ][] = &$comments[ $i ]; if ( 'trackback' === $type || 'pingback' === $type ) { $comments_by_type['pings'][] = &$comments[ $i ]; } } return $comments_by_type; }