カスタム投稿に専用の通し番号を付与する
functions.phpに以下を追加
1 2 3 4 5 6 7 8 9 10 11 12 | function get_post_number( $post_type = 'post' , $op = '<=' ) { global $wpdb , $post ; $post_type = is_array ( $post_type ) ? implode( "','" , $post_type ) : $post_type ; $number = $wpdb ->get_var(" SELECT COUNT ( * ) FROM $wpdb ->posts WHERE post_date { $op } '{$post->post_date}' AND post_status = 'publish' AND post_type = ( '{$post_type}' ) "); return $number ; } |
テンプレートに以下を貼り付ける。
1 | <?php echo get_post_number( $post ->post_type ); ?> |