
如何使用GitHub进行WordPress开发
_post_states ( $post, $display = true )
_post_states: 这个函数用于生成一个文章的状态。它需要一个参数,即$post,它是文章的对象: 这个函数在WordPress主题中经常被用来显示一个文章的状态。
以HTML形式呼应或返回文章的状态。
function _post_states( $post, $display = true ) { $post_states = get_post_states( $post ); $post_states_string = ''; if ( ! empty( $post_states ) ) { $state_count = count( $post_states ); $i = 0; $post_states_string .= ' — '; foreach ( $post_states as $state ) { ++$i; $separator = ( $i < $state_count ) ? ', ' : ''; $post_states_string .= "<span class='post-state'>{$state}{$separator}</span>"; } } if ( $display ) { echo $post_states_string; } return $post_states_string; }